From 5e4def0cd09db566e8c212c3fa7234dd3e23ee20 Mon Sep 17 00:00:00 2001 From: Shigma Date: Wed, 24 Apr 2024 23:13:13 +0800 Subject: [PATCH] fix(commands): handle nullable edge case, fix #323 --- plugins/commands/client/command.vue | 14 +++++++------- plugins/commands/client/commands.vue | 1 + plugins/commands/package.json | 2 +- plugins/commands/src/index.ts | 2 +- plugins/sandbox/src/message.ts | 6 +----- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/plugins/commands/client/command.vue b/plugins/commands/client/command.vue index bde94a95..2c028cf8 100644 --- a/plugins/commands/client/command.vue +++ b/plugins/commands/client/command.vue @@ -20,16 +20,16 @@
- {{ name }} + {{ name }} {{ stringify(alias) ? `(${stringify(alias)})` : '' }} {{ index > 0 ? '设为默认' : '显示名称' }} - + {{ command.initial.aliases[name] ? '禁用' : '删除' }} 恢复 @@ -80,7 +80,7 @@ @@ -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(' ') @@ -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({}) diff --git a/plugins/commands/client/commands.vue b/plugins/commands/client/commands.vue index 65aceb6e..11638bae 100644 --- a/plugins/commands/client/commands.vue +++ b/plugins/commands/client/commands.vue @@ -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 () => { diff --git a/plugins/commands/package.json b/plugins/commands/package.json index a9a4324b..994447b1 100644 --- a/plugins/commands/package.json +++ b/plugins/commands/package.json @@ -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": [ diff --git a/plugins/commands/src/index.ts b/plugins/commands/src/index.ts index 516b9bb9..e4e71db4 100644 --- a/plugins/commands/src/index.ts +++ b/plugins/commands/src/index.ts @@ -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) } diff --git a/plugins/sandbox/src/message.ts b/plugins/sandbox/src/message.ts index 69ee4961..731c350d 100644 --- a/plugins/sandbox/src/message.ts +++ b/plugins/sandbox/src/message.ts @@ -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' @@ -10,10 +9,7 @@ export class SandboxMessenger 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 })