Skip to content

Commit

Permalink
feat(core): support alias.filter
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 26, 2024
1 parent 8ea157b commit 5dee042
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/command/command.ts
Expand Up @@ -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')

Expand All @@ -18,6 +19,7 @@ export namespace Command {
export interface Alias {
options?: Dict
args?: string[]
filter?: Computed<boolean>
}

export interface Shortcut {
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/command/index.ts
Expand Up @@ -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) {
Expand Down

0 comments on commit 5dee042

Please sign in to comment.