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:
9 files changed
+147
-47
No files matched your search
@@ -51,6 +51,20 @@ export function GeneralSettingsTab({ config, onChange }: GeneralSettingsTabProps
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5 border-t pt-3">
|
||||
<Label className={sc.enabled ? undefined : 'text-muted-foreground'}>触发词</Label>
|
||||
<Input
|
||||
className="w-full font-mono"
|
||||
value={sc.trigger}
|
||||
disabled={!sc.enabled}
|
||||
maxLength={32}
|
||||
onChange={(e) => setStatusCommand({ trigger: e.target.value })}
|
||||
/>
|
||||
<p className="text-[11px] leading-relaxed text-muted-foreground">
|
||||
自定义触发词,默认 <code className="font-mono">#sl</code>。最长 32 字符,匹配前会去除首尾空格并转为小写。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start justify-between gap-3 border-t pt-3">
|
||||
<div className="min-w-0">
|
||||
<Label className={sc.enabled ? undefined : 'text-muted-foreground'}>不转发给下游(swallow)</Label>
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -97,11 +97,12 @@ export interface OneBotNetworks {
|
||||
wsClients: WsClientNetwork[];
|
||||
}
|
||||
|
||||
/** Built-in `#sl` status command settings (trigger word is hardcoded). */
|
||||
/** Built-in status command settings. Trigger word is configurable. */
|
||||
export interface StatusCommandConfig {
|
||||
enabled: boolean;
|
||||
swallow: boolean;
|
||||
cooldownSeconds: number;
|
||||
trigger: string;
|
||||
}
|
||||
|
||||
export interface OneBotConfig {
|
||||
|
||||
Reference in new issue
Block a user