Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: koishijs/koishi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e80defc63b0d8890c6ce0e1275fb70427b62d526
Choose a base ref
..
head repository: koishijs/koishi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b07aba7f3c7f551b203112c0779b6e42c5beaf41
Choose a head ref
Showing with 9 additions and 7 deletions.
  1. +3 −2 plugins/a11y/rate-limit/src/index.ts
  2. +1 −1 plugins/a11y/rate-limit/src/locales/zh.yml
  3. +3 −4 plugins/a11y/rate-limit/tests/index.spec.ts
  4. +2 −0 plugins/common/help/src/index.ts
5 changes: 3 additions & 2 deletions plugins/a11y/rate-limit/src/index.ts
Original file line number Diff line number Diff line change
@@ -46,6 +46,8 @@ export function apply(ctx: Context) {
const { maxUsage, minInterval } = command.config
let shouldFetchUsage = !!(maxUsage || minInterval)
for (const { name, notUsage } of Object.values(command._options)) {
// --help is not a usage (#772)
if (name === 'help') continue
if (name in options && notUsage) shouldFetchUsage = false
}
if (shouldFetchUsage) {
@@ -66,8 +68,7 @@ export function apply(ctx: Context) {

let isUsage = true
for (const { name, notUsage } of Object.values(command._options)) {
// --help is not a usage (#772)
if (name in options && (notUsage || name === 'help')) isUsage = false
if (name in options && notUsage) isUsage = false
}

// check usage
2 changes: 1 addition & 1 deletion plugins/a11y/rate-limit/src/locales/zh.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
internal:
usage-exhausted: 调用次数已达上限。
too-frequent: 调用过于频繁,请稍后再试。
option-not-usage: 不计入调用
option-not-usage: ' (不计入调用)'
command-max-usage: 已调用次数:{0}/{1}。
command-min-interval: 距离下次调用还需:{0}/{1} 秒。

7 changes: 3 additions & 4 deletions plugins/a11y/rate-limit/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ import { App, Time } from 'koishi'
import mock from '@koishijs/plugin-mock'
import memory from '@koishijs/plugin-database-memory'
import * as help from '@koishijs/plugin-help'
import * as admin from '@koishijs/plugin-admin'
import * as rate from '@koishijs/plugin-rate-limit'
import { install } from '@sinonjs/fake-timers'

@@ -12,7 +11,6 @@ let now = Date.now()
app.plugin(help)
app.plugin(mock)
app.plugin(memory)
app.plugin(admin)
app.plugin(rate)

const client1 = app.mock.client('123')
@@ -35,12 +33,13 @@ describe('@koishijs/plugin-rate-limit', () => {
.action(() => 'test')

it('Extended Help', async () => {
await client1.shouldReply('help foo', [
await client1.shouldReply('help foo -H', [
'foo',
'指令1',
'已调用次数:1/3。',
'可用的选项有:',
' --opt1 选项1(不计入调用)',
' -h, --help 显示此信息 (不计入调用)',
' --opt1 选项1 (不计入调用)',
' --opt2 选项2',
].join('\n'))
})
2 changes: 2 additions & 0 deletions plugins/common/help/src/index.ts
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@ export const Config: Schema<Config> = Schema.object({
export function enableHelp<U extends User.Field, G extends Channel.Field, A extends any[], O extends {}>(cmd: Command<U, G, A, O>) {
return cmd.option('help', '-h', {
hidden: true,
// @ts-ignore
notUsage: true,
descPath: 'commands.help.options.help',
})
}