Skip to content

Commit

Permalink
fix(commands): handle nullable edge case, fix #323
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 25, 2024
1 parent c1a839a commit 5e4def0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
14 changes: 7 additions & 7 deletions plugins/commands/client/command.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
<table>
<tr v-for="([name, alias], index) in Object.entries(current.aliases)" :key="name">
<td class="text-left">
<span class="alias-name" :class="{ disabled: alias.filter === false }">{{ name }}</span>
<span class="alias-name" :class="{ disabled: alias?.filter === false }">{{ name }}</span>
{{ stringify(alias) ? `(${stringify(alias)})` : '' }}
</td>
<td class="text-right">
<el-button
v-if="index > 0"
:disabled="alias.filter === false"
:disabled="alias?.filter === false"
@click="setDefault(name)"
>{{ index > 0 ? '设为默认' : '显示名称' }}</el-button>
<el-button v-if="alias.filter !== false" @click="deleteAlias(name)">
<el-button v-if="alias?.filter !== false" @click="deleteAlias(name)">
{{ command.initial.aliases[name] ? '禁用' : '删除' }}
</el-button>
<el-button v-else @click="recoverAlias(name)">恢复</el-button>
Expand Down Expand Up @@ -80,7 +80,7 @@
</div>
<template #footer>
<el-button @click="showAliasDialog = false">取消</el-button>
<el-button type="primary" :disabled="invalidName || parsed.error" @click="onEnter">确定</el-button>
<el-button type="primary" :disabled="invalidName || !!parsed.error" @click="onEnter">确定</el-button>
</template>
</el-dialog>
</template>
Expand Down Expand Up @@ -160,8 +160,8 @@ function recoverAlias(name: string) {
function stringify(alias: Command.Alias) {
return [
...alias.args || [],
...Object.entries(alias.options || {}).map(([key, value]) => {
...alias?.args || [],
...Object.entries(alias?.options || {}).map(([key, value]) => {
return value === true ? `--${key}` : `--${key}=${value}`
}),
].join(' ')
Expand All @@ -178,7 +178,7 @@ const aliases = computed(() => {
})
const invalidName = computed(() => {
return !inputName.value || aliases.value[inputName.value]
return !inputName.value || !!aliases.value[inputName.value]
})
const parsed = ref<Argv>({})
Expand Down
1 change: 1 addition & 0 deletions plugins/commands/client/commands.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function handleDrop(source: Node, target: Node, position: 'before' | 'after' | '
async function onEnter() {
await send('command/create', inputText.value)
inputText.value = ''
showCreateDialog.value = false
}
onActivated(async () => {
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.5.1",
"version": "3.5.2",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
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 @@ -214,7 +214,7 @@ export class CommandManager {
this.config[command.name] ||= {}
this.config[command.name].name = `${command.parent?.name || ''}/${command.displayName}`
this.config[command.name].aliases = filterKeys(aliases, (key, value) => {
return !deepEqual(initial.aliases[key], value || null)
return !deepEqual(initial.aliases[key], value, true)
})
this.write(command)
}
Expand Down
6 changes: 1 addition & 5 deletions plugins/sandbox/src/message.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Context, Dict, h, MessageEncoder, Random } from 'koishi'
import FileType from 'file-type'
import {} from '@koishijs/assets'
import { SandboxBot } from './bot'

Expand All @@ -10,10 +9,7 @@ export class SandboxMessenger<C extends Context = Context> extends MessageEncode
return [type, async (attrs) => {
const src = attrs.src || attrs.url
const type1 = type === 'image' ? 'img' : type
if (src.startsWith('base64://')) {
const { mime } = await FileType.fromBuffer(Buffer.from(src.slice(9), 'base64'))
return h(type1, { ...attrs, src: `data:${mime};base64,${src.slice(9)}` })
} else if (src.startsWith('file:') && this.bot.ctx.assets) {
if (src.startsWith('file:') && this.bot.ctx.assets) {
return h(type1, { ...attrs, src: await this.bot.ctx.assets.upload(src, src) })
}
return h(type1, { ...attrs, src })
Expand Down

0 comments on commit 5e4def0

Please sign in to comment.