2022-07-29 01:42:35 +08:00
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
return randomStr;
|
|
|
|
|
}
|
2022-08-01 23:13:34 +08:00
|
|
|
|
/**
|
|
|
|
|
* 发送私聊消息,仅给好友发送
|
|
|
|
|
* @param user_id qq号
|
|
|
|
|
* @param msg 消息
|
|
|
|
|
*/
|
|
|
|
|
export async function relpyPrivate (userId, msg) {
|
|
|
|
|
userId = Number(userId)
|
|
|
|
|
let friend = Bot.fl.get(userId)
|
|
|
|
|
if (friend) {
|
2022-08-10 20:15:49 +08:00
|
|
|
|
Bot.logger.mark(`发送好友消息[${friend.nickname}](${userId})`)
|
2022-08-01 23:13:34 +08:00
|
|
|
|
return await Bot.pickUser(userId).sendMsg(msg).catch((err) => {
|
2022-08-10 20:15:49 +08:00
|
|
|
|
Bot.logger.mark(err)
|
2022-08-01 23:13:34 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-03 09:57:59 +08:00
|
|
|
|
export async function replyMake(e,_msg,lenght){
|
|
|
|
|
let nickname = Bot.nickname;
|
|
|
|
|
if (e.isGroup) {
|
|
|
|
|
let info = await Bot.getGroupMemberInfo(e.group_id, Bot.uin)
|
|
|
|
|
nickname = info.card || info.nickname
|
|
|
|
|
}
|
|
|
|
|
let msgList=[];
|
|
|
|
|
for(let [index,item] of Object.entries(_msg)){
|
|
|
|
|
if(index<lenght){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
msgList.push({
|
|
|
|
|
message: item,
|
|
|
|
|
nickname: nickname,
|
|
|
|
|
user_id: Bot.uin
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
e._reply(await Bot.makeForwardMsg(msgList));
|
|
|
|
|
}
|
2022-07-29 01:42:35 +08:00
|
|
|
|
export default {
|
|
|
|
|
sleepAsync,
|
2022-09-03 09:57:59 +08:00
|
|
|
|
randomSleepAsync,replyMake,
|
2022-08-01 23:13:34 +08:00
|
|
|
|
randomString,relpyPrivate
|
2022-07-29 01:42:35 +08:00
|
|
|
|
}
|