Skip to content

Commit 7a5bb65

Browse files
committed
fix(core): send hint when arg prompt timeout, fix #1284
1 parent d2d815c commit 7a5bb65

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

packages/core/src/command/validate.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isNullable } from 'cosmokit'
12
import { Context } from '../context'
23
import { Argv } from './parser'
34

@@ -39,6 +40,9 @@ export default function validate(ctx: Context) {
3940
session.text(`commands.${command.name}.arguments.${decl.name}`),
4041
]))
4142
const source = await session.prompt()
43+
if (isNullable(source)) {
44+
return sendHint('internal.insufficient-arguments', decl.name)
45+
}
4246
args.push(Argv.parseValue(source, 'argument', argv, decl))
4347
index++
4448
}

packages/core/src/i18n.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class I18n {
8585
private* set(locale: string, prefix: string, value: I18n.Node): Generator<string> {
8686
if (typeof value === 'object' && value && !prefix.includes('@')) {
8787
for (const key in value) {
88+
if (key.startsWith('_')) continue
8889
yield* this.set(locale, prefix + key + '.', value[key])
8990
}
9091
} else if (prefix.includes('@')) {

packages/core/tests/runtime.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { App, User, Channel, Command, sleep } from 'koishi'
22
import mock, { DEFAULT_SELF_ID } from '@koishijs/plugin-mock'
33
import memory from '@koishijs/plugin-database-memory'
4+
import { install } from '@sinonjs/fake-timers'
45

56
const app = new App()
67

@@ -224,6 +225,19 @@ describe('Runtime', () => {
224225
await client4.shouldReply('bar baz', 'cmd1:bar baz')
225226
await client4.shouldReply('cmd1 foo bar', '存在多余参数,输入帮助以查看用法。')
226227
cmd1.config.showWarning = false
228+
cmd1.config.checkArgCount = false
229+
})
230+
231+
it('check arg count: timeout', async () => {
232+
const clock = install()
233+
cmd1.config.checkArgCount = true
234+
cmd1.config.showWarning = true
235+
await client4.shouldReply('cmd1', '请发送arg1。')
236+
await clock.runAllAsync()
237+
await client4.shouldReply('', '缺少参数,输入帮助以查看用法。')
238+
cmd1.config.showWarning = false
239+
cmd1.config.checkArgCount = false
240+
clock.uninstall()
227241
})
228242

229243
it('check unknown option', async () => {

0 commit comments

Comments
 (0)