2026-02-01 10:03:47 +09:00
|
|
|
import type { CommandHandler } from "./commands-types.js";
|
2026-01-14 09:11:16 +00:00
|
|
|
import { logVerbose } from "../../globals.js";
|
|
|
|
|
import { handleBashChatCommand } from "./bash-command.js";
|
|
|
|
|
|
2026-01-14 14:31:43 +00:00
|
|
|
export const handleBashCommand: CommandHandler = async (params, allowTextCommands) => {
|
2026-01-31 16:19:20 +09:00
|
|
|
if (!allowTextCommands) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-01-14 09:11:16 +00:00
|
|
|
const { command } = params;
|
|
|
|
|
const bashSlashRequested =
|
2026-01-14 14:31:43 +00:00
|
|
|
command.commandBodyNormalized === "/bash" || command.commandBodyNormalized.startsWith("/bash ");
|
2026-01-14 09:11:16 +00:00
|
|
|
const bashBangRequested = command.commandBodyNormalized.startsWith("!");
|
2026-01-14 14:31:43 +00:00
|
|
|
if (!bashSlashRequested && !(bashBangRequested && command.isAuthorizedSender)) {
|
2026-01-14 09:11:16 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (!command.isAuthorizedSender) {
|
2026-01-14 14:31:43 +00:00
|
|
|
logVerbose(`Ignoring /bash from unauthorized sender: ${command.senderId || "<unknown>"}`);
|
2026-01-14 09:11:16 +00:00
|
|
|
return { shouldContinue: false };
|
|
|
|
|
}
|
|
|
|
|
const reply = await handleBashChatCommand({
|
|
|
|
|
ctx: params.ctx,
|
|
|
|
|
cfg: params.cfg,
|
|
|
|
|
agentId: params.agentId,
|
|
|
|
|
sessionKey: params.sessionKey,
|
|
|
|
|
isGroup: params.isGroup,
|
|
|
|
|
elevated: params.elevated,
|
|
|
|
|
});
|
|
|
|
|
return { shouldContinue: false, reply };
|
|
|
|
|
};
|