fix for doubling plugins in memory

pull/29/head
Mallory Hancock 2018-03-15 12:04:58 -07:00
parent 0476ddd5df
commit 7faea22fe1
3 changed files with 16 additions and 20 deletions

View File

@ -23,7 +23,7 @@ class Bot(irc.bot.SingleServerIRCBot):
self.bot_nick = nickname self.bot_nick = nickname
self.start_logging(self.log_level) self.start_logging(self.log_level)
self.load_plugins() self.load_plugins()
class Message: class Message:
def __init__(self, channel, nick, botnick, ops, logger, cmd=None, arg=None, text=None, nick_list=None): def __init__(self, channel, nick, botnick, ops, logger, cmd=None, arg=None, text=None, nick_list=None):
self.channel = channel self.channel = channel
@ -104,14 +104,10 @@ class Bot(irc.bot.SingleServerIRCBot):
except Exception as e: except Exception as e:
self.logger.exception('could not load plugin') self.logger.exception('could not load plugin')
# gather all commands and listeners # gather all commands and listeners
self.cmds = {}
self.lstnrs = {}
for cmd in pinhook.plugin.cmds: for cmd in pinhook.plugin.cmds:
self.logger.debug('adding command {}'.format(cmd['cmd'])) self.logger.debug('adding command {}'.format(cmd['cmd']))
self.cmds[cmd['cmd']] = cmd['func']
for lstnr in pinhook.plugin.lstnrs: for lstnr in pinhook.plugin.lstnrs:
self.logger.debug('adding listener {}'.format(lstnr['lstn'])) self.logger.debug('adding listener {}'.format(lstnr['lstn']))
self.lstnrs[lstnr['lstn']] = lstnr['func']
def on_welcome(self, c, e): def on_welcome(self, c, e):
if self.ns_pass: if self.ns_pass:
@ -165,9 +161,9 @@ class Bot(irc.bot.SingleServerIRCBot):
self.logger.info('reloading plugins per request of {}'.format(nick)) self.logger.info('reloading plugins per request of {}'.format(nick))
self.load_plugins() self.load_plugins()
c.privmsg(chan, 'Plugins reloaded') c.privmsg(chan, 'Plugins reloaded')
elif cmd in self.cmds: elif cmd in pinhook.plugin.cmds:
try: try:
output = self.cmds[cmd](self.Message( output = pinhook.plugin.cmds[cmd](self.Message(
channel=chan, channel=chan,
cmd=cmd, cmd=cmd,
nick_list=list(self.channels[chan].users()), nick_list=list(self.channels[chan].users()),
@ -182,9 +178,9 @@ class Bot(irc.bot.SingleServerIRCBot):
except Exception as e: except Exception as e:
self.logger.exception('issue with command {}'.format(cmd)) self.logger.exception('issue with command {}'.format(cmd))
else: else:
for lstnr in self.lstnrs: for lstnr in pinhook.plugin.lstnrs:
try: try:
output = self.lstnrs[lstnr](self.Message( output = pinhook.plugin.lstnrs[lstnr](self.Message(
channel=chan, channel=chan,
text=text, text=text,
nick_list=list(self.channels[chan].users()), nick_list=list(self.channels[chan].users()),

View File

@ -1,5 +1,5 @@
cmds = [] cmds = {}
lstnrs = [] lstnrs = {}
class Output: class Output:
@ -22,8 +22,12 @@ def message(msg):
return Output('message', msg) return Output('message', msg)
def add_plugin(command, func): def _add_plugin(command, func):
cmds.append({'cmd': command, 'func': func}) cmds[command] = func
def _add_listener(name, func):
lstnrs[name] = func
def clear_plugins(): def clear_plugins():
@ -31,19 +35,15 @@ def clear_plugins():
lstnrs.clear() lstnrs.clear()
def add_listener(name, func):
lstnrs.append({'lstn': name, 'func': func})
def register(command): def register(command):
def register_for_command(func): def register_for_command(func):
add_plugin(command, func) _add_plugin(command, func)
return func return func
return register_for_command return register_for_command
def listener(name): def listener(name):
def register_as_listener(func): def register_as_listener(func):
add_listener(name, func) _add_listener(name, func)
return func return func
return register_as_listener return register_as_listener

View File

@ -72,7 +72,7 @@ class UploadCommand(Command):
# Where the magic happens: # Where the magic happens:
setup( setup(
name=NAME, name=NAME,
version='1.4.0', version='1.4.1b1',
description=DESCRIPTION, description=DESCRIPTION,
long_description=long_description, long_description=long_description,
author=AUTHOR, author=AUTHOR,