Files
openclaw/src/auto-reply/command-detection.ts

34 lines
1.1 KiB
TypeScript
Raw Normal View History

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