chore: initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import type {Socket} from 'socket.io-client';
|
||||
import {get_function_list} from '../../../bot/function/init.ts';
|
||||
import {console_print} from '../../../utils/console_print.ts';
|
||||
|
||||
export async function update_function_list(
|
||||
socket: Socket,
|
||||
node_id: number,
|
||||
is_current: () => boolean = () => socket.connected,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const function_list = await get_function_list();
|
||||
if (!socket.connected || !is_current()) return;
|
||||
const response = await socket.timeout(5000).emitWithAck('update_function_list', {
|
||||
id: node_id,
|
||||
function_list,
|
||||
});
|
||||
if (!socket.connected || !is_current()) return;
|
||||
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) {
|
||||
if (!socket.connected || !is_current()) return;
|
||||
throw new Error(`函数列表上报失败: ${error instanceof Error ? error.message : String(error)}`, {cause: error});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user