Skip to content

Commit

Permalink
feat(plugin-common): support at syntax in contextify
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 15, 2020
1 parent 522605a commit 1576873
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/plugin-common/src/contextify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context } from 'koishi-core'
import { Context, getTargetId } from 'koishi-core'

export default function apply (ctx: Context) {
ctx.command('contextify <message...>', '在特定上下文中触发指令', { authority: 3 })
Expand Down Expand Up @@ -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('权限不足。')
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-common/tests/contextify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 选项。')
Expand Down

0 comments on commit 1576873

Please sign in to comment.