From 4054276ac0dbc684063587bb5036e9d7908d6085 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Thu, 7 Apr 2016 22:46:08 +1000 Subject: [PATCH] games: Clean up CommandHandler --- plugins/games.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/games.py b/plugins/games.py index 9742392..032825b 100644 --- a/plugins/games.py +++ b/plugins/games.py @@ -16,8 +16,18 @@ exportdb_timer = None dbname = utils.getDatabaseName('pylinkgames') -# command handler -class command_handler: + +# commands +class Command: + def __init__(self, irc, name, args, sender, target): + self.irc = irc + self.name = name + self.args = args + self.sender = sender + self.target = target + + +class CommandHandler: def __init__(self): self.public_command_prefix = '.' self.commands = {} @@ -71,12 +81,20 @@ class command_handler: command_name = command_name.casefold() + command = Command(irc, command_name, command_args, numeric, target) + # check for matching handler and dispatch handler = self.commands.get(command_name) if handler: - handler(self, irc, command_name, command_args) + handler(self, command) -cmdhandler = command_handler() +cmdhandler = CommandHandler() + +def help_cmd(command_handler, command): + "[command] -- Help for the given commands" + print('COMMAND DETAILS:', command) + +cmdhandler.add_command('help', help_cmd) # loading def main(irc=None):