feat(game-commands): add generic argument parser and integrate for mina, pelear, pescar

This commit is contained in:
2025-10-05 19:34:45 -05:00
parent 1b1aa40358
commit 66a984d74e
4 changed files with 61 additions and 26 deletions

View File

@@ -30,3 +30,38 @@ export async function findBestToolKey(userId: string, guildId: string, toolType:
return best?.key ?? null;
}
export interface ParsedGameArgs {
areaKey: string;
levelArg: number | null;
providedTool: string | null;
}
const AREA_OVERRIDE_PREFIX = 'area:';
export function parseGameArgs(args: string[], defaultAreaKey: string): ParsedGameArgs {
const tokens = args.filter((arg): arg is string => typeof arg === 'string' && arg.trim().length > 0);
let areaKey = defaultAreaKey;
let levelArg: number | null = null;
let providedTool: string | null = null;
for (const token of tokens) {
if (token.startsWith(AREA_OVERRIDE_PREFIX)) {
const override = token.slice(AREA_OVERRIDE_PREFIX.length).trim();
if (override) areaKey = override;
continue;
}
if (levelArg === null && /^\d+$/.test(token)) {
levelArg = parseInt(token, 10);
continue;
}
if (!providedTool) {
providedTool = token;
}
}
return { areaKey, levelArg, providedTool };
}