From 823b9852a9239cad890a61237409fbeb796a5ee6 Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 21 May 2025 13:03:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=BC=83=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/reportBots.js | 20 ++------------------ lib/core/botControl.js | 39 --------------------------------------- 2 files changed, 2 insertions(+), 57 deletions(-) diff --git a/apps/reportBots.js b/apps/reportBots.js index b1e5035..e33731e 100644 --- a/apps/reportBots.js +++ b/apps/reportBots.js @@ -12,12 +12,12 @@ export default class ReportBots extends plugin { reg: '^#crystelf同步$', fnc: 'manualReport', permission: 'master', - }, + } /*, { reg: '^#crystelf广播(.+)$', fnc: 'broadcast', permission: 'master', - }, + },*/, ], }); schedule.scheduleJob('*/30 * * * *', () => this.autoReport()); @@ -41,20 +41,4 @@ export default class ReportBots extends plugin { e.reply('crystelf Bot同步失败:核心未连接..', true); } } - - async broadcast(e) { - const msg = e?.msg?.match(/^#crystelf广播(.+)$/)?.[1]?.trim(); - if (!msg) { - return e.reply('广播内容不能为空'); - } - - e.reply(`开始广播消息到所有群(内容:${msg})..`); - - try { - await botControl.broadcastMessage(msg); - } catch (err) { - logger.error(`广播执行异常: ${err.message}`); - return e.reply('广播过程中发生错误,请检查日志..'); - } - } } diff --git a/lib/core/botControl.js b/lib/core/botControl.js index 1a85bf8..9076783 100644 --- a/lib/core/botControl.js +++ b/lib/core/botControl.js @@ -93,45 +93,6 @@ const botControl = { return false; } }, - - /** - * 广播消息到所有群聊 - * @param message 消息 - * @returns {Promise} - */ - async broadcastMessage(message) { - const groupMap = new Map(); - - for (const bot of Object.values(Bot)) { - if (!bot?.uin || !bot.gl) continue; - for (const [groupId, groupInfo] of bot.gl.entries()) { - if (!groupMap.has(groupId)) { - groupMap.set(groupId, []); - } - groupMap.get(groupId).push(bot); - } - } - const tasks = []; - for (const [groupId, botList] of groupMap.entries()) { - const delay = Math.floor(30_000 + Math.random() * 60_000); //30s-90s - const bot = botList[Math.floor(Math.random() * botList.length)]; - const task = setTimeout(async () => { - try { - const group = bot.pickGroup(groupId); - if (!group) { - logger.warn(`无法发消息到群${groupId}`); - return; - } - await group.send(message); - logger.mark(`已广播消息到群 ${groupId}(Bot ${bot.uin}),延迟 ${delay / 1000}s`); - } catch (err) { - logger.error(`广播到群 ${groupId} 失败:${err}`); - } - }, delay); - tasks.push(task); - } - logger.info(`广播任务已部署,总群数:${groupMap.size}`); - }, }; export default botControl;