Skip to content

Commit 4ffd32a

Browse files
committed
fix(core): allow mention in session.suggest(), fix #1295
1 parent 56cd4a9 commit 4ffd32a

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

packages/core/src/locales/zh-CN.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal:
3030
invalid-user: 请指定正确的用户。
3131
invalid-channel: 请指定正确的频道。
3232
suggest-hint: 您要找的是不是{0}?
33-
suggest-command: 发送句号以使用推测的指令
33+
suggest-command: 回复句号以使用推测的指令
3434

3535
commands:
3636
$: 指令系统

packages/core/src/session.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,9 @@ export class Session<U extends User.Field = never, G extends Channel.Field = nev
471471

472472
await this.send(prefix + options.suffix)
473473
return this.prompt((session) => {
474-
const content = session.content.trim()
475-
if (!content || content === '.' || content === '。') {
474+
const { content, atSelf, hasAt } = session.stripped
475+
if (!atSelf && hasAt) return
476+
if (content === '.' || content === '。') {
476477
return expect[0]
477478
}
478479
}, options)

packages/core/tests/suggest.spec.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Command Suggestion', () => {
2121

2222
it('execute command', async () => {
2323
await client1.shouldReply('foo bar', 'foobar')
24-
await client1.shouldNotReply(' ')
24+
await client1.shouldNotReply('.')
2525
})
2626

2727
it('no suggestions', async () => {
@@ -31,32 +31,32 @@ describe('Command Suggestion', () => {
3131
it('apply suggestions 1', async () => {
3232
await client1.shouldReply('fo bar', '您要找的是不是“foo”?发送句号以使用推测的指令。')
3333
await client2.shouldReply('/fooo -t bar', 'fooobar')
34-
await client1.shouldReply(' ', 'foobar')
35-
await client1.shouldNotReply(' ')
34+
await client1.shouldReply('.', 'foobar')
35+
await client1.shouldNotReply('.')
3636
})
3737

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

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

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

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

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

8585
it('no suggestions', async () => {
86-
await client.shouldNotReply(' ')
86+
await client.shouldNotReply('.')
8787
await client.shouldNotReply('find for')
8888
})
8989

9090
it('show suggestions', async () => {
9191
await client.shouldReply('.find 111', 'PREFIX')
92-
await client.shouldNotReply(' ')
92+
await client.shouldNotReply('.')
9393
await client.shouldReply('.find for', `PREFIX您要找的是不是“foo”?SUFFIX`)
94-
await client.shouldReply(' ', 'found:foo')
94+
await client.shouldReply('.', 'found:foo')
9595
await client.shouldReply('.find bax', `PREFIX您要找的是不是“bar”或“baz”?`)
96-
await client.shouldNotReply(' ')
96+
await client.shouldNotReply('.')
9797
})
9898
})

0 commit comments

Comments
 (0)