fix: relax slash command parsing

This commit is contained in:
Peter Steinberger
2026-01-08 03:22:14 +01:00
parent 36b443f4f3
commit ad5c87c193
18 changed files with 226 additions and 31 deletions

View File

@@ -1,17 +1,19 @@
import { listChatCommands } from "./commands-registry.js";
import { listChatCommands, normalizeCommandBody } from "./commands-registry.js";
export function hasControlCommand(text?: string): boolean {
if (!text) return false;
const trimmed = text.trim();
if (!trimmed) return false;
const lowered = trimmed.toLowerCase();
const normalizedBody = normalizeCommandBody(trimmed);
if (!normalizedBody) return false;
const lowered = normalizedBody.toLowerCase();
for (const command of listChatCommands()) {
for (const alias of command.textAliases) {
const normalized = alias.trim().toLowerCase();
if (!normalized) continue;
if (lowered === normalized) return true;
if (command.acceptsArgs && lowered.startsWith(normalized)) {
const nextChar = trimmed.charAt(normalized.length);
const nextChar = normalizedBody.charAt(normalized.length);
if (nextChar && /\s/.test(nextChar)) return true;
}
}