diff --git a/pinhook/bot.py b/pinhook/bot.py index 62297cb..5b6bdbe 100644 --- a/pinhook/bot.py +++ b/pinhook/bot.py @@ -23,7 +23,7 @@ class Bot(irc.bot.SingleServerIRCBot): self.bot_nick = nickname self.start_logging(self.log_level) self.load_plugins() - + class Message: def __init__(self, channel, nick, botnick, ops, logger, cmd=None, arg=None, text=None, nick_list=None): self.channel = channel @@ -104,14 +104,10 @@ class Bot(irc.bot.SingleServerIRCBot): except Exception as e: self.logger.exception('could not load plugin') # gather all commands and listeners - self.cmds = {} - self.lstnrs = {} for cmd in pinhook.plugin.cmds: self.logger.debug('adding command {}'.format(cmd['cmd'])) - self.cmds[cmd['cmd']] = cmd['func'] for lstnr in pinhook.plugin.lstnrs: self.logger.debug('adding listener {}'.format(lstnr['lstn'])) - self.lstnrs[lstnr['lstn']] = lstnr['func'] def on_welcome(self, c, e): if self.ns_pass: @@ -165,9 +161,9 @@ class Bot(irc.bot.SingleServerIRCBot): self.logger.info('reloading plugins per request of {}'.format(nick)) self.load_plugins() c.privmsg(chan, 'Plugins reloaded') - elif cmd in self.cmds: + elif cmd in pinhook.plugin.cmds: try: - output = self.cmds[cmd](self.Message( + output = pinhook.plugin.cmds[cmd](self.Message( channel=chan, cmd=cmd, nick_list=list(self.channels[chan].users()), @@ -182,9 +178,9 @@ class Bot(irc.bot.SingleServerIRCBot): except Exception as e: self.logger.exception('issue with command {}'.format(cmd)) else: - for lstnr in self.lstnrs: + for lstnr in pinhook.plugin.lstnrs: try: - output = self.lstnrs[lstnr](self.Message( + output = pinhook.plugin.lstnrs[lstnr](self.Message( channel=chan, text=text, nick_list=list(self.channels[chan].users()), diff --git a/pinhook/plugin.py b/pinhook/plugin.py index 807575c..0607ba6 100644 --- a/pinhook/plugin.py +++ b/pinhook/plugin.py @@ -1,5 +1,5 @@ -cmds = [] -lstnrs = [] +cmds = {} +lstnrs = {} class Output: @@ -22,8 +22,12 @@ def message(msg): return Output('message', msg) -def add_plugin(command, func): - cmds.append({'cmd': command, 'func': func}) +def _add_plugin(command, func): + cmds[command] = func + + +def _add_listener(name, func): + lstnrs[name] = func def clear_plugins(): @@ -31,19 +35,15 @@ def clear_plugins(): lstnrs.clear() -def add_listener(name, func): - lstnrs.append({'lstn': name, 'func': func}) - - def register(command): def register_for_command(func): - add_plugin(command, func) + _add_plugin(command, func) return func return register_for_command def listener(name): def register_as_listener(func): - add_listener(name, func) + _add_listener(name, func) return func return register_as_listener diff --git a/setup.py b/setup.py index 2f548db..633a964 100755 --- a/setup.py +++ b/setup.py @@ -72,7 +72,7 @@ class UploadCommand(Command): # Where the magic happens: setup( name=NAME, - version='1.4.0', + version='1.4.1b1', description=DESCRIPTION, long_description=long_description, author=AUTHOR,