mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-07-04 06:09:19 +00:00
删除弃用代码
This commit is contained in:
parent
655f5a312b
commit
823b9852a9
@ -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('广播过程中发生错误,请检查日志..');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,45 +93,6 @@ const botControl = {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 广播消息到所有群聊
|
||||
* @param message 消息
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user