Added a callback manager (#2)

Co-authored-by: Cynopolis <megaveganzombie@gmail.com>
This commit is contained in:
Cynopolis
2025-04-02 13:44:42 -04:00
committed by GitHub
parent 976d2453a2
commit 185182b92f
2 changed files with 68 additions and 45 deletions

18
CommandHandler.py Normal file
View File

@@ -0,0 +1,18 @@
class CommandHandler:
def __init__(self, print_method):
self.commands: dict = {}
self.print = print_method
def register_callback(self, key: str, callback):
self.commands[key.lower()] = callback
def parse_command(self, command : str):
args :list[str] = command.split(" ")
if args[0].lower() in self.commands:
return_message = self.commands[args[0].lower()](args[1:])
if not (return_message is None):
self.print(return_message)
else:
self.print("Command not recognized. Type 'help' for a list of commands.")