refactor: merge /spark command into /roll
Consolidate the `/spark` command into `/roll` to simplify the CLI. The `/roll` command now handles both dice notation and spark table slugs. - Update `parseInput` to treat `/roll` arguments as a generic string. - Update `dispatchCommand` to check for spark table matches before evaluating dice notation or variable expressions. - Update command completions to show both dice and spark table suggestions under `/roll`. - Update documentation and UI placeholders to reflect the change.
This commit is contained in:
@@ -12,23 +12,17 @@ export interface CompletionItem {
|
||||
}
|
||||
|
||||
export interface ParsedInput {
|
||||
type: "chat" | "roll" | "spark" | "link" | "set" | "rolltag";
|
||||
type: "chat" | "roll" | "link" | "set" | "rolltag";
|
||||
payload: Record<string, unknown>;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export function parseInput(raw: string): ParsedInput {
|
||||
if (raw.startsWith("/roll ")) {
|
||||
const notation = raw.slice("/roll ".length).trim();
|
||||
if (!notation)
|
||||
return { type: "roll", payload: {}, error: "需要骰子表达式" };
|
||||
return { type: "roll", payload: { notation, label: notation } };
|
||||
}
|
||||
|
||||
if (raw.startsWith("/spark ")) {
|
||||
const key = raw.slice("/spark ".length).trim();
|
||||
if (!key) return { type: "spark", payload: {}, error: "需要种子表键名" };
|
||||
return { type: "spark", payload: { key } };
|
||||
const arg = raw.slice("/roll ".length).trim();
|
||||
if (!arg)
|
||||
return { type: "roll", payload: {}, error: "需要骰子表达式或种子表键名" };
|
||||
return { type: "roll", payload: { arg } };
|
||||
}
|
||||
|
||||
if (raw.startsWith("/link ")) {
|
||||
@@ -69,7 +63,7 @@ export function parseInput(raw: string): ParsedInput {
|
||||
return { type: "set", payload: { key, expr } };
|
||||
}
|
||||
|
||||
if (raw === "/roll" || raw === "/spark" || raw === "/link" || raw === "/set") {
|
||||
if (raw === "/roll" || raw === "/link" || raw === "/set") {
|
||||
return { type: "chat", payload: {}, error: "请补全命令" };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user