Skip to content

Commit

Permalink
fix(teach): fix incorrect auth checks for context, fix #208
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 9, 2021
1 parent 6c59d86 commit 89d53b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
atri
dist
lib
build/*.js

/build/*.js
2 changes: 1 addition & 1 deletion packages/plugin-teach/src/plugins/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function apply(ctx: Context, config: Dialogue.Config) {
.option('enableGlobal', '-E 在所有环境下启用问答', { authority })
.option('groups', '-g <gids:string> 设置具体的生效环境', { authority, type: RE_GROUPS })
.option('global', '-G 无视上下文搜索')
.check(({ options, session }) => {
.action(({ options, session }) => {
if (options.disable && options.enable) {
return '选项 -d, -e 不能同时使用。'
} else if (options.disableGlobal && options.enableGlobal) {
Expand Down
7 changes: 6 additions & 1 deletion packages/plugin-teach/tests/context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const DETAIL_HEAD = '编号为 1 的问答信息:\n问题:foo\n回答:bar\
const SEARCH_HEAD = '问题“foo”的回答如下:\n'

describe('Teach Plugin - Context', () => {
const { u3, u3g1, u3g2 } = createEnvironment({ useContext: true })
const { u3, u3g1, u3g2, u2g1 } = createEnvironment({ useContext: true })

it('validate options 1', async () => {
await u3.shouldReply('# foo bar', '非群聊上下文中请使用 -E/-D 进行操作或指定 -g, --groups 选项。')
Expand Down Expand Up @@ -68,4 +68,9 @@ describe('Teach Plugin - Context', () => {
await u3g1.shouldReply('#1', DETAIL_HEAD + '生效环境:除本群')
await u3g1.shouldReply('## foo -G', SEARCH_HEAD + '1. [d] bar')
})

it('validate options 3', async () => {
await u2g1.shouldReply('# foo baz -E', '权限不足。')
await u2g1.shouldReply('# foo baz', '问答已添加,编号为 2。')
})
})

0 comments on commit 89d53b1

Please sign in to comment.