Files
node_server/bot/function/bot/stop_current_function.ts
T
2026-10-22 17:07:08 +08:00

20 lines
870 B
TypeScript

import type {Bot} from '@wp2508/mineflayer';
import type {BaseFunction} from '../../../types/bot/function/function.ts';
import {cancel_functions} from '../cancellation.ts';
export class init implements BaseFunction<[]> {
readonly name = 'stop_current_function';
readonly i18n = {lang: 'zh-CN', name: '停止当前函数', description: '立即取消当前和排队函数,停止挖掘、使用物品并释放所有控制键'};
readonly args: [] = [];
async run(bot: Bot, args: []): Promise<boolean> {
if (!Array.isArray(args) || args.length !== 0) return false;
let success = true;
for (const stop of [() => cancel_functions(bot), () => bot.stopDigging(),
() => bot.deactivateItem(), () => bot.clearControlStates()]) {
try { stop(); } catch { success = false; }
}
return success;
}
}