Do initial work
This commit is contained in:
parent
5eb9031583
commit
9aa3f39e9b
16
bot.py
16
bot.py
|
@ -2,6 +2,7 @@ import teambot, sys, traceback, imp, plugin, os
|
|||
|
||||
BOTOP = "~minerobber@127.0.0.1"
|
||||
PREFIX = "!"
|
||||
PLUGIN_MODULES = dict()
|
||||
|
||||
class MinerbotPhoenix(teambot.Handler):
|
||||
def on_connection_established(self,*args):
|
||||
|
@ -10,11 +11,16 @@ class MinerbotPhoenix(teambot.Handler):
|
|||
plugin.clear()
|
||||
for name in os.listdir("plugins"):
|
||||
if name.endswith(".py"):
|
||||
bot.handler.load_module(name[:-3])
|
||||
def load_module(self,modname):
|
||||
bot.handler.load_module(name[:-3],os.path.join("plugins",name))
|
||||
def load_module(self,modname,path):
|
||||
if modname in PLUGIN_MODULES:
|
||||
importlib.reload(PLUGIN_MODULES[modname])
|
||||
return
|
||||
try:
|
||||
fp, pathname, desc = imp.find_module(modname,["plugins"])
|
||||
imp.load_module(modname,fp,pathname,desc)
|
||||
spec = importlib.util.spec_from_file_location(modname,path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
PLUGIN_MODULES[modname]=module
|
||||
except:
|
||||
print("Unable to load plugin {}".format(modname))
|
||||
traceback.print_exc()
|
||||
|
@ -39,5 +45,5 @@ class MinerbotPhoenix(teambot.Handler):
|
|||
|
||||
if __name__=="__main__":
|
||||
channels = "#bots".split()
|
||||
bot = teambot.TeamBot(channels,"minerbot","localhost",username="Minerbot",chandler=MinerbotPhoenix)
|
||||
bot = teambot.TeamBot(channels,"minerbot2","localhost",username="Minerbot",chandler=MinerbotPhoenix)
|
||||
bot.start()
|
||||
|
|
Loading…
Reference in New Issue