fix: 打招呼增加cd

This commit is contained in:
ikechan8370 2023-03-06 10:38:56 +08:00
parent 8ed19c7f5c
commit 1368c168cc
2 changed files with 13 additions and 4 deletions

View file

@ -52,12 +52,16 @@ export class Entertainment extends plugin {
}
async sendRandomMessage () {
logger.info('开始处理ChatGPT随机打招呼。')
if (Config.debug) {
logger.info('开始处理ChatGPT随机打招呼。')
}
let toSend = Config.initiativeChatGroups || []
for (let i = 0; i < toSend.length; i++) {
let groupId = parseInt(toSend[i])
if (Bot.getGroupList().get(groupId)) {
if (Math.floor(Math.random() * 100) < 10) {
// 5%的概率打招呼
if (Math.floor(Math.random() * 100) < 5 && !(await redis.get(`CHATGPT:HELLO_GROUP:${groupId}`))) {
await redis.set(`CHATGPT:HELLO_GROUP:${groupId}`, '1', { EX: 3600 * 6 })
let message = await generateHello()
logger.info(`打招呼给群聊${groupId}` + message)
if (Config.defaultUseTTS) {
@ -67,10 +71,10 @@ export class Entertainment extends plugin {
await Bot.sendGroupMsg(groupId, message)
}
} else {
logger.info(`这次就不打招呼给群聊${groupId}`)
logger.info(`时机未到,这次就不打招呼给群聊${groupId}`)
}
} else {
logger.warn('机器人不在要发送的群组里,忽略群' + groupId)
logger.warn('机器人不在要发送的群组里,忽略群。同时建议检查配置文件修改要打招呼的群号。' + groupId)
}
}
}