diff --git a/packages/plugin-common/src/contextify.ts b/packages/plugin-common/src/contextify.ts index 40624a1b97..9e9954853a 100644 --- a/packages/plugin-common/src/contextify.ts +++ b/packages/plugin-common/src/contextify.ts @@ -1,4 +1,4 @@ -import { Context } from 'koishi-core' +import { Context, getTargetId } from 'koishi-core' export default function apply (ctx: Context) { ctx.command('contextify ', '在特定上下文中触发指令', { authority: 3 }) @@ -31,7 +31,8 @@ export default function apply (ctx: Context) { const newMeta = { ...meta } let user = meta.$user if (options.user) { - const id = +options.user + const id = getTargetId(options.user) + if (!id) return meta.$send('未指定目标。') user = await ctx.database.observeUser(id) if (meta.$user.authority <= user.authority) { return meta.$send('权限不足。') diff --git a/packages/plugin-common/tests/contextify.spec.ts b/packages/plugin-common/tests/contextify.spec.ts index 930c440a07..cc04392b2a 100644 --- a/packages/plugin-common/tests/contextify.spec.ts +++ b/packages/plugin-common/tests/contextify.spec.ts @@ -22,6 +22,7 @@ beforeAll(async () => { test('check input', async () => { await session1.shouldHaveReply('ctxf -u 456', '请输入要发送的文本。') + await session2.shouldHaveReply('ctxf -m foo show-context', '未指定目标。') await session1.shouldHaveReply('ctxf show-context', '请提供新的上下文。') await session1.shouldHaveReply('ctxf -u 789 show-context', '权限不足。') await session1.shouldHaveReply('ctxf -m 456 show-context', '无法在私聊上下文使用 --member 选项。')