2026-01-11 02:17:10 +01:00
|
|
|
import type { ClawdbotConfig } from "../config/types.js";
|
|
|
|
|
import {
|
2026-01-11 21:06:04 +05:30
|
|
|
type CommandNormalizeOptions,
|
2026-01-11 02:17:10 +01:00
|
|
|
listChatCommands,
|
|
|
|
|
listChatCommandsForConfig,
|
|
|
|
|
normalizeCommandBody,
|
|
|
|
|
} from "./commands-registry.js";
|
2026-01-05 01:31:36 +01:00
|
|
|
|
2026-01-11 02:17:10 +01:00
|
|
|
export function hasControlCommand(
|
|
|
|
|
text?: string,
|
|
|
|
|
cfg?: ClawdbotConfig,
|
2026-01-11 21:06:04 +05:30
|
|
|
options?: CommandNormalizeOptions,
|
2026-01-11 02:17:10 +01:00
|
|
|
): boolean {
|
2026-01-05 01:31:36 +01:00
|
|
|
if (!text) return false;
|
|
|
|
|
const trimmed = text.trim();
|
|
|
|
|
if (!trimmed) return false;
|
2026-01-11 21:06:04 +05:30
|
|
|
const normalizedBody = normalizeCommandBody(trimmed, options);
|
2026-01-08 03:22:14 +01:00
|
|
|
if (!normalizedBody) return false;
|
|
|
|
|
const lowered = normalizedBody.toLowerCase();
|
2026-01-11 02:17:10 +01:00
|
|
|
const commands = cfg ? listChatCommandsForConfig(cfg) : listChatCommands();
|
|
|
|
|
for (const command of commands) {
|
2026-01-06 14:17:56 -06:00
|
|
|
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)) {
|
2026-01-08 03:22:14 +01:00
|
|
|
const nextChar = normalizedBody.charAt(normalized.length);
|
2026-01-06 14:17:56 -06:00
|
|
|
if (nextChar && /\s/.test(nextChar)) return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2026-01-05 01:31:36 +01:00
|
|
|
}
|