mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:21:35 +00:00
refactor(auto-reply): share set/unset command action parsing
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { parseSetUnsetCommand } from "./commands-setunset.js";
|
||||
import { parseSetUnsetCommandAction } from "./commands-setunset.js";
|
||||
import { parseSlashCommandOrNull } from "./commands-slash-parse.js";
|
||||
|
||||
export type ConfigCommand =
|
||||
@@ -18,22 +18,23 @@ export function parseConfigCommand(raw: string): ConfigCommand | null {
|
||||
return { action: "error", message: parsed.message };
|
||||
}
|
||||
const { action, args } = parsed;
|
||||
const setUnset = parseSetUnsetCommandAction<ConfigCommand>({
|
||||
slash: "/config",
|
||||
action,
|
||||
args,
|
||||
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", path: args || undefined };
|
||||
case "get":
|
||||
return { action: "show", path: args || undefined };
|
||||
case "unset":
|
||||
case "set": {
|
||||
const parsed = parseSetUnsetCommand({ slash: "/config", action, args });
|
||||
if (parsed.kind === "error") {
|
||||
return { action: "error", message: parsed.message };
|
||||
}
|
||||
return parsed.kind === "set"
|
||||
? { action: "set", path: parsed.path, value: parsed.value }
|
||||
: { action: "unset", path: parsed.path };
|
||||
}
|
||||
default:
|
||||
return {
|
||||
action: "error",
|
||||
|
||||
Reference in New Issue
Block a user