2
0
mirror of https://github.com/ctrlcvs/xiaoyao-cvs-plugin.git synced 2024-12-23 03:20:52 +08:00
xiaoyao-cvs-plugin/model/mys/utils.js

45 lines
1.0 KiB
JavaScript

import _ from 'lodash';
export async function sleepAsync(sleepms) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, sleepms)
});
}
export async function randomSleepAsync(){
let sleep = 2 * 1000 + _.random(3 * 1000);
await sleepAsync(sleep);
}
export function randomString(length){
let randomStr = '';
for (let i = 0; i < length; i++) {
randomStr += _.sample('abcdefghijklmnopqrstuvwxyz0123456789');
// randomStr += _.sample('dWCcD2FsOUXEstC5f9xubswZxEeoBOTc');
}
return randomStr;
}
/**
* 发送私聊消息,仅给好友发送
* @param user_id qq号
* @param msg 消息
*/
export async function relpyPrivate (userId, msg) {
userId = Number(userId)
let friend = Bot.fl.get(userId)
if (friend) {
Bot.logger.mark(`发送好友消息[${friend.nickname}](${userId})`)
return await Bot.pickUser(userId).sendMsg(msg).catch((err) => {
Bot.logger.mark(err)
})
}
}
export default {
sleepAsync,
randomSleepAsync,
randomString,relpyPrivate
}