Skip to content

Commit

Permalink
fix(core): disable command
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 30, 2020
1 parent fb7dbe6 commit 1cffdab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions packages/koishi-core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ export class App extends Context {
const user = await this.database.observeUser(meta.userId, Array.from(userFields))
Object.defineProperty(meta, '$user', { value: user, writable: true })

// ignore some user calls
if (user.flag & UserFlag.ignore) return

// emit attach event
this.emitEvent(meta, 'attach', meta)

// ignore some user calls
if (user.flag & UserFlag.ignore) return
}

// execute command
Expand Down Expand Up @@ -381,8 +381,8 @@ export class App extends Context {

parseCommandLine (message: string, meta: Meta<'message'>): ParsedCommandLine {
const name = message.split(/\s/, 1)[0].toLowerCase()
const command = this._commandMap[name]
if (command?.context.match(meta)) {
const command = this.getCommand(name, meta)
if (command) {
const result = command.parse(message.slice(name.length).trimStart())
return { meta, command, ...result }
}
Expand Down
5 changes: 3 additions & 2 deletions packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,15 @@ export class Context {
}

private _getCommandByRawName (name: string) {
name = name.split(' ', 1)[0]
const index = name.lastIndexOf('/')
return this.app._commandMap[name.slice(index + 1).toLowerCase()]
}

getCommand (name: string, meta: Meta<'message'>) {
const command = this._getCommandByRawName(name)
if (command?.context.match(meta) && !command.getConfig('disable', meta)) return command
if (command?.context.match(meta) && !command.getConfig('disable', meta)) {
return command
}
}

runCommand (name: string, meta: Meta<'message'>, args: string[] = [], options: Record<string, any> = {}, rest = '') {
Expand Down

0 comments on commit 1cffdab

Please sign in to comment.