Add bot frame to make prefix command actually work
This commit is contained in:
parent
79cc9ee811
commit
32992fe67f
28
bot.py
28
bot.py
|
@ -2,11 +2,11 @@ import teambot, sys, traceback, plugin, os
|
|||
import impmod
|
||||
|
||||
BOTOP = "~minerobber@127.0.0.1"
|
||||
PREFIX = "!"
|
||||
PLUGIN_MODULES = dict()
|
||||
PLUGIN_SPECS = dict()
|
||||
|
||||
class MinerbotPhoenix(teambot.Handler):
|
||||
prefix="!"
|
||||
def on_connection_established(self,*args):
|
||||
self.load_modules()
|
||||
def load_modules(self):
|
||||
|
@ -15,33 +15,37 @@ class MinerbotPhoenix(teambot.Handler):
|
|||
if name.endswith(".py"):
|
||||
bot.handler.load_module(name[:-3],os.path.join("plugins",name))
|
||||
def load_module(self,modname,path):
|
||||
if modname in PLUGIN_MODULES:
|
||||
print("{} already imported, reloading".format(modname))
|
||||
PLUGIN_MODULES[modname].reload()
|
||||
return
|
||||
try:
|
||||
print("importing {}".format(modname))
|
||||
PLUGIN_MODULES[modname]=impmod.Module(modname,path)
|
||||
if modname in PLUGIN_MODULES:
|
||||
print("{} already imported, reloading".format(modname))
|
||||
PLUGIN_MODULES[modname].reload()
|
||||
return
|
||||
try:
|
||||
print("importing {}".format(modname))
|
||||
PLUGIN_MODULES[modname]=impmod.Module(modname,path)
|
||||
except:
|
||||
print("Unable to load plugin {}".format(modname))
|
||||
traceback.print_exc()
|
||||
except:
|
||||
print("Unable to load plugin {}".format(modname))
|
||||
traceback.print_exc()
|
||||
pass
|
||||
def on_pubmsg(self,channel,nick,message):
|
||||
for listener in plugin.listeners:
|
||||
plugin.listeners[listener](self,channel,nick,message)
|
||||
if not message.startswith(PREFIX): return
|
||||
if not message.startswith(self.prefix): return
|
||||
self.is_admin = self.event.source.userhost == BOTOP
|
||||
args = message[len(PREFIX):].split(" ")
|
||||
args = message[len(self.prefix):].split(" ")
|
||||
cmd = args.pop(0).lower()
|
||||
self.cmd = cmd
|
||||
if cmd in plugin.cmds:
|
||||
try:
|
||||
plugin.cmds[cmd](self,channel,nick,*args)
|
||||
except TypeError:
|
||||
self.say(channel,"Usage: {}{} {}".format(PREFIX,cmd,plugin.help.get(cmd,"")))
|
||||
self.say(channel,"Usage: {}{} {}".format(self.prefix,cmd,plugin.help.get(cmd,"")))
|
||||
except Exception as e:
|
||||
errcls,err,tb = sys.exc_info()
|
||||
self.say(channel,"ACCESS VIOLATION: "+traceback.format_exception_only(errcls,err)[0].strip())
|
||||
print("On command `{}{} {}` by {}:".format(PREFIX,cmd," ".join(args),self.event.source))
|
||||
print("On command `{}{} {}` by {}:".format(self.prefix,cmd," ".join(args),self.event.source))
|
||||
traceback.print_exc()
|
||||
|
||||
if __name__=="__main__":
|
||||
|
|
Loading…
Reference in New Issue