diff --git a/packages/plugin-eval/src/index.ts b/packages/plugin-eval/src/index.ts index 27e9f98583..4771609f6e 100644 --- a/packages/plugin-eval/src/index.ts +++ b/packages/plugin-eval/src/index.ts @@ -1,4 +1,4 @@ -import { App, Context, User, Session } from 'koishi-core' +import { App, Context, Session } from 'koishi-core' import { CQCode, Logger, defineProperty, omit, Random } from 'koishi-utils' import { Worker, ResourceLimits } from 'worker_threads' import { WorkerAPI, WorkerConfig, WorkerData, Response } from './worker' @@ -14,6 +14,12 @@ declare module 'koishi-core/dist/app' { } } +declare module 'koishi-core/dist/command' { + interface CommandConfig { + noEval?: boolean + } +} + declare module 'koishi-core/dist/context' { interface EventMap { 'worker/start' (): void | Promise @@ -34,7 +40,6 @@ interface MainConfig { prefix?: string timeout?: number maxLogs?: number - prohibitedCommands?: string[] resourceLimits?: ResourceLimits } @@ -47,7 +52,6 @@ const defaultConfig: Config = { timeout: 1000, setupFiles: {}, maxLogs: Infinity, - prohibitedCommands: ['evaluate', 'echo', 'broadcast', 'teach', 'contextify'], } const logger = new Logger('eval') @@ -103,7 +107,7 @@ export function apply(ctx: Context, config: Config = {}) { workerData: { entry: process.env.KOISHI_WORKER_ENTRY, logLevels: Logger.levels, - ...omit(config, ['maxLogs', 'resourceLimits', 'timeout', 'prohibitedCommands']), + ...omit(config, ['maxLogs', 'resourceLimits', 'timeout']), }, resourceLimits: config.resourceLimits, }) @@ -141,12 +145,12 @@ export function apply(ctx: Context, config: Config = {}) { }) ctx.on('before-command', ({ command, session }) => { - if (config.prohibitedCommands.includes(command.name) && session._isEval) { + if (command.config.noEval && session._isEval) { return `不能在 evaluate 指令中调用 ${command.name} 指令。` } }) - const evaluate = ctx.command('evaluate [expr...]', '执行 JavaScript 脚本') + const evaluate = ctx.command('evaluate [expr...]', '执行 JavaScript 脚本', { noEval: true }) .alias('eval') .userFields(['authority']) .option('slient', '-s 不输出最后的结果') diff --git a/packages/plugin-teach/src/internal.ts b/packages/plugin-teach/src/internal.ts index f7d5df9682..31fd67b6b6 100644 --- a/packages/plugin-teach/src/internal.ts +++ b/packages/plugin-teach/src/internal.ts @@ -7,6 +7,12 @@ import { formatQuestionAnswers } from './search' import { format } from 'util' import leven from 'leven' +declare module 'koishi-core/dist/command' { + interface CommandConfig { + noInterp?: boolean + } +} + declare module 'koishi-core/dist/plugins/message' { namespace Message { export namespace Teach { @@ -169,9 +175,8 @@ export default function apply(ctx: Context, config: Dialogue.Config) { }) }) - const { prohibitedCommands = [] } = config ctx.on('before-command', ({ command, session }) => { - if (prohibitedCommands.includes(command.name) && session._redirected) { + if (command.config.noInterp && session._redirected) { return format(Message.Teach.ProhibitedCommand, command.name) } }) diff --git a/packages/plugin-teach/src/utils.ts b/packages/plugin-teach/src/utils.ts index b4d5a29699..35d4129682 100644 --- a/packages/plugin-teach/src/utils.ts +++ b/packages/plugin-teach/src/utils.ts @@ -70,7 +70,6 @@ export namespace Dialogue { prefix?: string historyAge?: number validateRegExp?: RegExpValidator.Options - prohibitedCommands?: string[] } export enum Flag {