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

@ -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()),

View File

@ -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

View File

@ -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,