Skip to content

Commit

Permalink
fix(commands): fix regression bug for new alias API
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 15, 2023
1 parent 64aef38 commit 24dd326
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
30 changes: 16 additions & 14 deletions plugins/commands/client/commands.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
<div class="aliases">
<h2 class="k-schema-header">名称设置</h2>
<ul>
<li v-for="(item, index) in current.aliases" :key="item">
<span>{{ item }}</span>
<li v-for="([name, item], index) in Object.entries(current.aliases)" :key="name">
<span>{{ name }}</span>
<span class="button"
v-if="index > 0"
@click.stop.prevent="setDefault(index)"
@click.stop.prevent="setDefault(name)"
>设置为默认</span>
<span class="button"
v-if="!command.initial.aliases.includes(item)"
@click.stop.prevent="deleteAlias(index)"
v-if="!command.initial.aliases[name]"
@click.stop.prevent="deleteAlias(name)"
>删除别名</span>
</li>
<li>
Expand Down Expand Up @@ -133,7 +133,7 @@ const aliases = computed(() => {
})
const invalid = computed(() => {
return !alias.value || aliases.value.includes(alias.value)
return !alias.value || aliases.value[alias.value]
})
const dialog = computed({
Expand Down Expand Up @@ -209,8 +209,8 @@ function handleDrop(source: Node, target: Node, position: 'before' | 'after' | '
async function onEnter() {
if (title.value === '添加指令') {
await send('command/create', alias.value)
} else if (alias.value && !current.value.aliases.includes(alias.value)) {
current.value.aliases.push(alias.value)
} else if (invalid.value) {
current.value.aliases[alias.value] = {}
await send('command/aliases', command.value.name, current.value.aliases)
}
alias.value = ''
Expand All @@ -225,15 +225,17 @@ function removeCommand() {
send('command/remove', command.value.name)
}
function setDefault(index: number) {
const item = current.value.aliases[index]
current.value.aliases.splice(index, 1)
current.value.aliases.unshift(item)
function setDefault(name: string) {
const item = current.value.aliases[name]
current.value.aliases = {
[name]: item,
...current.value.aliases,
}
send('command/aliases', command.value.name, current.value.aliases)
}
function deleteAlias(index: number) {
current.value.aliases.splice(index, 1)
function deleteAlias(name: string) {
delete current.value.aliases[name]
send('command/aliases', command.value.name, current.value.aliases)
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/commands/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@koishijs/plugin-commands",
"description": "Override Command Config for Koishi",
"version": "3.3.2",
"version": "3.3.4",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
6 changes: 3 additions & 3 deletions plugins/commands/src/console.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataService } from '@koishijs/console'
import { debounce } from 'throttle-debounce'
import { Command, Context } from 'koishi'
import { Command, Context, Dict } from 'koishi'
import { resolve } from 'path'
import { CommandManager, CommandState } from '.'

Expand All @@ -16,7 +16,7 @@ declare module '@koishijs/console' {
'command/remove'(name: string): void
'command/update'(name: string, config: Pick<CommandState, 'config' | 'options'>): void
'command/teleport'(name: string, parent: string): void
'command/aliases'(name: string, aliases: string[]): void
'command/aliases'(name: string, aliases: Dict<Command.Alias>): void
}
}

Expand Down Expand Up @@ -65,7 +65,7 @@ export default class CommandProvider extends DataService<CommandData[]> {

ctx.console.addListener('command/aliases', (name, aliases) => {
const { command } = manager.ensure(name)
manager.alias(command, Object.fromEntries(aliases.map(name => [name, {}])), true)
manager.alias(command, aliases, true)
this.refresh()
})

Expand Down
2 changes: 1 addition & 1 deletion plugins/commands/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class CommandManager {

// extend aliases and display name
this.alias(target, {
[name]: {},
...name ? { [name]: {} } : {},
...target._aliases,
...override.aliases,
})
Expand Down

0 comments on commit 24dd326

Please sign in to comment.