chore: initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import {get_bot_context_status} from "../../../bot/instance";
|
||||
import type {Socket} from "socket.io-client";
|
||||
import {console_print} from "../../../utils/console_print.ts";
|
||||
import {bot_status} from "../../../types/bot/instance/bot_runtime.ts";
|
||||
|
||||
export async function update_all_bot_status(socket: Socket, node_id: number) {
|
||||
const bot_status = await get_bot_context_status();
|
||||
if (!socket.connected) return;
|
||||
try {
|
||||
const response = await socket
|
||||
.timeout(5000)
|
||||
.emitWithAck('update_all_bot_status', {
|
||||
id: node_id,
|
||||
bot_status,
|
||||
});
|
||||
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)}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function update_one_bot_status(socket: Socket, node_id: number, bot_id: number, user_id: number, status: bot_status) {
|
||||
if (!socket.connected) return;
|
||||
try {
|
||||
const response = await socket
|
||||
.timeout(5000)
|
||||
.emitWithAck('update_one_bot_status', {
|
||||
id: node_id,
|
||||
user_id,
|
||||
bot_id,
|
||||
status,
|
||||
});
|
||||
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(`机器人 ${bot_id} 状态更新成功 更新为 ${status}`));
|
||||
} catch (error) {
|
||||
throw new Error(`机器人 ${bot_id} 状态上报失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
@@ -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});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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)}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import minecraftProtocol from "@wp2508/minecraft-protocol";
|
||||
import type {Socket} from "socket.io-client";
|
||||
import {console_print} from "../../../utils/console_print.ts";
|
||||
|
||||
export async function update_version_list(socket: Socket, node_id: number) {
|
||||
const version_list = minecraftProtocol.supportedVersions;
|
||||
try {
|
||||
const response = await socket
|
||||
.timeout(5000)
|
||||
.emitWithAck('update_version_list', {
|
||||
id: node_id,
|
||||
version_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)}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import type {Socket} from 'socket.io-client';
|
||||
import {get_workflow_catalog} from '../../../bot/workflow/catalog.ts';
|
||||
import {console_print} from '../../../utils/console_print.ts';
|
||||
|
||||
export async function update_workflow_catalog(
|
||||
socket: Socket,
|
||||
node_id: number,
|
||||
is_current: () => boolean = () => socket.connected,
|
||||
): Promise<void> {
|
||||
try {
|
||||
if (!socket.connected || !is_current()) return;
|
||||
const workflow_catalog = get_workflow_catalog();
|
||||
if (!socket.connected || !is_current()) return;
|
||||
const response = await socket.timeout(5000).emitWithAck('update_workflow_catalog', {
|
||||
id: node_id,
|
||||
workflow_catalog,
|
||||
});
|
||||
if (!socket.connected || !is_current()) return;
|
||||
if (!response || (response.status !== 'success' && response.status !== 'error')) {
|
||||
throw new Error('Invalid workflow catalog acknowledgement');
|
||||
}
|
||||
if (response.status === 'error') throw new Error('Workflow catalog report was rejected');
|
||||
console_print.log(console_print.success('工作流目录更新成功'));
|
||||
} catch {
|
||||
if (!socket.connected || !is_current()) return;
|
||||
throw new Error('Workflow catalog report failed');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user