Skip to content

Commit

Permalink
fix: output help message when parameter is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikoTan committed Dec 31, 2023
1 parent 55ff7ca commit 303b96f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/i18n/en-US/macrodict.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ commands:
lang: Specify the language of the output.

messages:
no_macro: 'Error: Please enter the command with macro.'
wrong_language: 'Invalid language {0}. Trying to search macros with default language {1}.'
not_found_puppeteer: 'Plugin puppeteer was not found, could not render text commands.'
not_found_macro: 'Macro not found.'
Expand Down
1 change: 1 addition & 0 deletions src/i18n/zh-CN/macrodict.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ commands:
textMode: 输出为文本模式

messages:
no_macro: 错误:使用指令时应当传递宏名称。
wrong_language: '不存在语言 {0},将采用默认语言 {1} 进行搜索。'
not_found_puppeteer: '未找到 koishi-plugin-puppeteer 插件,无法渲染宏指令。'
not_found_macro: '找不到宏指令。'
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context } from 'koishi'
import { Context, h } from 'koishi'

import { Config } from './config'
import i18n from './i18n'
Expand Down Expand Up @@ -29,6 +29,9 @@ export async function apply(ctx: Context, config: Config): Promise<void> {
.channelFields(['macrodict'])
.option('lang', '-l <language:string>')
.action(async ({ session, options }, macro) => {
if (!macro?.trim?.()) {
return h('message', [h('p', session?.text('.no_macro')), h('br'), h('execute', 'help macrodict')])
}
let lang = (options?.lang as Locale) ?? config.defaultLanguage
if (!lang || !locales.includes(lang)) {
session?.sendQueued(session.text('.wrong_language', [lang, config.defaultLanguage]))
Expand Down

0 comments on commit 303b96f

Please sign in to comment.