mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:01:36 +00:00
refactor(auto-reply): share slash set/unset command parsing
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { parseSetUnsetCommandAction } from "./commands-setunset.js";
|
||||
import { parseSlashCommandOrNull } from "./commands-slash-parse.js";
|
||||
import { parseSlashCommandWithSetUnset } from "./commands-setunset.js";
|
||||
|
||||
export type DebugCommand =
|
||||
| { action: "show" }
|
||||
@@ -9,37 +8,22 @@ export type DebugCommand =
|
||||
| { action: "error"; message: string };
|
||||
|
||||
export function parseDebugCommand(raw: string): DebugCommand | null {
|
||||
const parsed = parseSlashCommandOrNull(raw, "/debug", {
|
||||
invalidMessage: "Invalid /debug syntax.",
|
||||
});
|
||||
if (!parsed) {
|
||||
return null;
|
||||
}
|
||||
if (!parsed.ok) {
|
||||
return { action: "error", message: parsed.message };
|
||||
}
|
||||
const { action, args } = parsed;
|
||||
const setUnset = parseSetUnsetCommandAction<DebugCommand>({
|
||||
return parseSlashCommandWithSetUnset<DebugCommand>({
|
||||
raw,
|
||||
slash: "/debug",
|
||||
action,
|
||||
args,
|
||||
invalidMessage: "Invalid /debug syntax.",
|
||||
usageMessage: "Usage: /debug show|set|unset|reset",
|
||||
onKnownAction: (action) => {
|
||||
if (action === "show") {
|
||||
return { action: "show" };
|
||||
}
|
||||
if (action === "reset") {
|
||||
return { action: "reset" };
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
onSet: (path, value) => ({ action: "set", path, value }),
|
||||
onUnset: (path) => ({ action: "unset", path }),
|
||||
onError: (message) => ({ action: "error", message }),
|
||||
});
|
||||
if (setUnset) {
|
||||
return setUnset;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case "show":
|
||||
return { action: "show" };
|
||||
case "reset":
|
||||
return { action: "reset" };
|
||||
default:
|
||||
return {
|
||||
action: "error",
|
||||
message: "Usage: /debug show|set|unset|reset",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user