feat: make #sl status command trigger configurable (exact match, max 32 char) (#138)

* feat: make #sl status command trigger configurable (exact match, max 32 char)

The trigger word for the built-in #sl status command is now configurable
via statusCommand.trigger, with exact case-insensitive matching preserved.

* chore: reject control chars in trigger + add sync assertion
This commit is contained in:
stla authored and GitHub committed 2026-06-25 01:02:17 +08:00
1 parent 19c03eb0ba
commit 41bad7f24c
9 files changed
+147 -47

No files matched your search

+9 -1
View File
@@ -1,6 +1,11 @@
import type { MessageFormat, OneBotConfig, StatusCommandConfig } from '@/types';
const DEFAULT_STATUS_COMMAND: StatusCommandConfig = { enabled: true, swallow: false, cooldownSeconds: 5 };
const DEFAULT_STATUS_COMMAND: StatusCommandConfig = {
enabled: true,
swallow: false,
cooldownSeconds: 5,
trigger: '#sl',
};
/** Fill the `statusCommand` block with defaults when the backend omits or
* partially supplies it (older configs predate the feature). */
@@ -13,6 +18,9 @@ function normalizeStatusCommand(raw: unknown): StatusCommandConfig {
typeof src.cooldownSeconds === 'number' && Number.isFinite(src.cooldownSeconds) && src.cooldownSeconds >= 0
? Math.trunc(src.cooldownSeconds)
: DEFAULT_STATUS_COMMAND.cooldownSeconds,
trigger: typeof src.trigger === 'string' && src.trigger.trim().length > 0 && !/[\r\n]/.test(src.trigger)
? src.trigger.trim().slice(0, 32)
: DEFAULT_STATUS_COMMAND.trigger,
};
}