Skip to content

Commit

Permalink
fix(core): allow mention in session.suggest(), fix #1295
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 3, 2023
1 parent 56cd4a9 commit e08f6e0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal:
invalid-user: 请指定正确的用户。
invalid-channel: 请指定正确的频道。
suggest-hint: 您要找的是不是{0}?
suggest-command: 发送句号以使用推测的指令
suggest-command: 回复句号以使用推测的指令

commands:
$: 指令系统
5 changes: 3 additions & 2 deletions packages/core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,9 @@ export class Session<U extends User.Field = never, G extends Channel.Field = nev

await this.send(prefix + options.suffix)
return this.prompt((session) => {
const content = session.content.trim()
if (!content || content === '.' || content === '。') {
const { content, atSelf, hasAt } = session.stripped
if (!atSelf && hasAt) return
if (content === '.' || content === '。') {
return expect[0]
}
}, options)
Expand Down
32 changes: 16 additions & 16 deletions packages/core/tests/suggest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,42 @@ describe('Command Suggestion', () => {

it('execute command', async () => {
await client1.shouldReply('foo bar', 'foobar')
await client1.shouldNotReply(' ')
await client1.shouldNotReply('.')
})

it('no suggestions', async () => {
await client1.shouldNotReply('bar foo')
})

it('apply suggestions 1', async () => {
await client1.shouldReply('fo bar', '您要找的是不是“foo”?发送句号以使用推测的指令。')
await client1.shouldReply('fo bar', '您要找的是不是“foo”?回复句号以使用推测的指令。')
await client2.shouldReply('/fooo -t bar', 'fooobar')
await client1.shouldReply(' ', 'foobar')
await client1.shouldNotReply(' ')
await client1.shouldReply('.', 'foobar')
await client1.shouldNotReply('.')
})

it('apply suggestions 2', async () => {
await client2.shouldReply('/foooo -t bar', '您要找的是不是“fooo”?发送句号以使用推测的指令。')
await client2.shouldReply('/foooo -t bar', '您要找的是不是“fooo”?回复句号以使用推测的指令。')
await client1.shouldReply('foo bar', 'foobar')
await client2.shouldReply(' ', 'fooobar')
await client2.shouldNotReply(' ')
await client2.shouldReply('.', 'fooobar')
await client2.shouldNotReply('.')
})

it('ignore suggestions 1', async () => {
await client1.shouldReply('fo bar', '您要找的是不是“foo”?发送句号以使用推测的指令。')
await client1.shouldReply('fo bar', '您要找的是不是“foo”?回复句号以使用推测的指令。')
await client1.shouldNotReply('bar foo')
await client1.shouldNotReply(' ')
await client1.shouldNotReply('.')
})

it('ignore suggestions 2', async () => {
await client2.shouldReply('/fo bar', '您要找的是不是“foo”?发送句号以使用推测的指令。')
await client2.shouldReply('/fo bar', '您要找的是不是“foo”?回复句号以使用推测的指令。')
await client2.shouldReply('/foo bar', 'foobar')
await client2.shouldNotReply(' ')
await client2.shouldNotReply('.')
})

it('multiple suggestions', async () => {
await client1.shouldReply('fool bar', '您要找的是不是“foo”或“fooo”或“bool”?')
await client1.shouldNotReply(' ')
await client1.shouldNotReply('.')
})
})

Expand All @@ -83,16 +83,16 @@ describe('session.suggest()', () => {
after(() => app.stop())

it('no suggestions', async () => {
await client.shouldNotReply(' ')
await client.shouldNotReply('.')
await client.shouldNotReply('find for')
})

it('show suggestions', async () => {
await client.shouldReply('.find 111', 'PREFIX')
await client.shouldNotReply(' ')
await client.shouldNotReply('.')
await client.shouldReply('.find for', `PREFIX您要找的是不是“foo”?SUFFIX`)
await client.shouldReply(' ', 'found:foo')
await client.shouldReply('.', 'found:foo')
await client.shouldReply('.find bax', `PREFIX您要找的是不是“bar”或“baz”?`)
await client.shouldNotReply(' ')
await client.shouldNotReply('.')
})
})

0 comments on commit e08f6e0

Please sign in to comment.