Move module loading into bot function and add clearing of cache

This commit is contained in:
minerobber 2018-12-15 06:50:00 +00:00
parent fd668a6124
commit e588ffbb5d
2 changed files with 12 additions and 3 deletions

10
bot.py
View File

@ -4,6 +4,13 @@ BOTOP = "~minerobber@127.0.0.1"
PREFIX = "!"
class MinerbotPhoenix(teambot.Handler):
def on_connection_established(self,*args):
self.load_modules()
def load_modules(self):
plugin.clear()
for name in os.listdir("plugins"):
if name.endswith(".py"):
bot.handler.load_module(name[:-3])
def load_module(self,modname):
try:
fp, pathname, desc = imp.find_module(modname,["plugins"])
@ -33,7 +40,4 @@ class MinerbotPhoenix(teambot.Handler):
if __name__=="__main__":
channels = "#bots".split()
bot = teambot.TeamBot(channels,"minerbot","localhost",chandler=MinerbotPhoenix)
for name in os.listdir("plugins"):
if name.endswith(".py"):
bot.handler.load_module(name[:-3])
bot.start()

View File

@ -2,6 +2,11 @@ cmds = {}
help = {}
listeners = {}
def clear():
cmds.clear()
help.clear()
listeners.clear()
def command(name,helptext="No help available for this command."):
def _register_cmd(func):
cmds[name]=func