mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-07-05 14:39:18 +00:00
自动/手动上报bots详情
id,群聊
This commit is contained in:
parent
0d44015957
commit
69877be997
35
apps/reportBots.js
Normal file
35
apps/reportBots.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import botControl from '../lib/core/botControl.js';
|
||||||
|
|
||||||
|
export default class ReportBots extends plugin {
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
name: 'crystelf Bot状态上报',
|
||||||
|
dsc: '定时上报botID和群聊列表',
|
||||||
|
rule: [
|
||||||
|
{
|
||||||
|
reg: '^#crystelf同步$',
|
||||||
|
fnc: 'manualReport',
|
||||||
|
permission: 'master',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
task: {
|
||||||
|
name: 'crystelf定时同步',
|
||||||
|
corn: '0 */30 * * * *',
|
||||||
|
fnc: 'autoReport',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async autoReport() {
|
||||||
|
await botControl.reportBots();
|
||||||
|
}
|
||||||
|
|
||||||
|
async manualReport(e) {
|
||||||
|
let success = await botControl.reportBots();
|
||||||
|
if (success) {
|
||||||
|
e.reply('crystelf Bot信息已同步到核心..');
|
||||||
|
} else {
|
||||||
|
e.reply('crystelf Bot同步失败:核心未连接..');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
lib/core/botControl.js
Normal file
33
lib/core/botControl.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import wsClient from '../../models/ws/wsClient.js';
|
||||||
|
|
||||||
|
const botControl = {
|
||||||
|
async reportBots() {
|
||||||
|
const bots = [];
|
||||||
|
|
||||||
|
for (const bot of Object.values(Bot)) {
|
||||||
|
if (!bot || !bot.uin) continue;
|
||||||
|
|
||||||
|
const botInfo = {
|
||||||
|
uin: bot.uin,
|
||||||
|
groups: [],
|
||||||
|
};
|
||||||
|
let groupsMap = bot.gl;
|
||||||
|
if (groupsMap) {
|
||||||
|
for (const [groupId, groupInfo] of groupsMap) {
|
||||||
|
botInfo.groups.push({
|
||||||
|
group_id: groupId,
|
||||||
|
group_name: groupInfo.group_name || '未知',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bots.push(botInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await wsClient.sendMessage({
|
||||||
|
type: 'reportBots',
|
||||||
|
data: bots,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default botControl;
|
@ -66,8 +66,10 @@ class WsClient {
|
|||||||
async sendMessage(msg) {
|
async sendMessage(msg) {
|
||||||
if (this.ws?.readyState === WebSocket.OPEN) {
|
if (this.ws?.readyState === WebSocket.OPEN) {
|
||||||
this.ws.send(JSON.stringify(msg));
|
this.ws.send(JSON.stringify(msg));
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
logger.warn('crystelf WS 服务器未连接,无法发送消息..');
|
logger.warn('crystelf WS 服务器未连接,无法发送消息..');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user