feat: expenses, report and day log commands

This commit is contained in:
2025-01-18 21:21:26 +01:00
parent a28d392342
commit 8681914be2
30 changed files with 5614 additions and 1 deletions

40
utils/registry.ts Normal file
View File

@@ -0,0 +1,40 @@
import { ShortcutsResponse } from './types';
import { pingCommand } from './commands/ping';
import { diaryCommand } from './commands/diary';
import { CommandParser, diaryCommands } from './commands/commandParser';
type CommandHandler = (
parameters?: Record<string, string>
) => Promise<ShortcutsResponse>;
export class CommandRegistry {
private commands: Map<string, CommandHandler>;
private parser: CommandParser;
constructor() {
this.commands = new Map();
this.parser = new CommandParser();
this.registerDefaultCommands();
}
private registerDefaultCommands() {
this.commands.set('ping', pingCommand);
this.commands.set('diary', diaryCommand);
diaryCommands.forEach(cmd => {
this.parser.registerCommand(cmd);
});
}
register(command: string, handler: CommandHandler) {
this.commands.set(command.toLowerCase(), handler);
}
getCommand(command: string): CommandHandler | undefined {
return this.commands.get(command.toLowerCase());
}
getParser(): CommandParser {
return this.parser;
}
}