From 5dee0426c3e0fe39a00e0da9e84d20569f5492a7 Mon Sep 17 00:00:00 2001 From: Shigma Date: Sat, 27 Jan 2024 01:39:31 +0800 Subject: [PATCH] feat(core): support alias.filter --- packages/core/src/command/command.ts | 2 ++ packages/core/src/command/index.ts | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/src/command/command.ts b/packages/core/src/command/command.ts index 731cc410d..bb88641ef 100644 --- a/packages/core/src/command/command.ts +++ b/packages/core/src/command/command.ts @@ -7,6 +7,7 @@ import { Channel, User } from '../database' import { FieldCollector, Session } from '../session' import { Permissions } from '../permission' import { Context } from '../context' +import { Computed } from '../filter' const logger = new Logger('command') @@ -18,6 +19,7 @@ export namespace Command { export interface Alias { options?: Dict args?: string[] + filter?: Computed } export interface Shortcut { diff --git a/packages/core/src/command/index.ts b/packages/core/src/command/index.ts index 9fed58787..e6b6a857a 100644 --- a/packages/core/src/command/index.ts +++ b/packages/core/src/command/index.ts @@ -236,8 +236,11 @@ export class Commander { }) } - get(name: string, strict?: boolean) { - return this._commandList.find(cmd => strict ? cmd.name === name : cmd._aliases[name]) + get(name: string, session?: Session) { + return this._commandList.find((cmd) => { + const alias = cmd._aliases[name] + return alias && (session?.resolve(alias.filter) ?? true) + }) } updateCommands(bot: Bot) {