26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
import {Socket} from "socket.io";
|
|
import {get_plugin_list} from "../../../bot/plugins/init.ts";
|
|
import {console_print} from "../../../utils/console_print.ts";
|
|
|
|
export async function update_plugins(socket: Socket, node_id: number, is_current: () => boolean = () => socket.connected) {
|
|
const plugin_list = await get_plugin_list();
|
|
if (!socket.connected || !is_current()) return;
|
|
try {
|
|
const response = await socket
|
|
.timeout(5000)
|
|
.emitWithAck('update_plugins', {
|
|
id: node_id,
|
|
plugin_list,
|
|
});
|
|
if (!response || (response.status !== 'success' && response.status !== 'error')) {
|
|
throw new Error('响应格式无效');
|
|
}
|
|
if (response.status === 'error') {
|
|
throw new Error(`收到错误码: ${response.data}`);
|
|
}
|
|
console_print.log(console_print.success("支持的插件列表更新成功"))
|
|
} catch (error) {
|
|
throw new Error(`插件列表上报失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
}
|
|
}
|