Make bot not crash during plugin reload
This commit is contained in:
parent
7c12644ef9
commit
8accdfbdba
20
bot.py
20
bot.py
|
@ -8,16 +8,13 @@ PLUGIN_SPECS = dict()
|
|||
class MinerbotPhoenix(teambot.Handler):
|
||||
prefix="!"
|
||||
nick="minerbot"
|
||||
loading=False
|
||||
def on_connection_established(self,*args):
|
||||
self.load_modules()
|
||||
def load_modules(self):
|
||||
self.loading = True
|
||||
plugin.clear()
|
||||
for name in os.listdir("plugins"):
|
||||
if name.endswith(".py"):
|
||||
bot.handler.load_module(name[:-3],os.path.join("plugins",name))
|
||||
self.loading = False
|
||||
def load_module(self,modname,path):
|
||||
try:
|
||||
if modname in PLUGIN_MODULES:
|
||||
|
@ -34,14 +31,17 @@ class MinerbotPhoenix(teambot.Handler):
|
|||
traceback.print_exc()
|
||||
pass
|
||||
def on_pubmsg(self,channel,nick,message):
|
||||
if self.loading: return
|
||||
self.is_admin = self.event.source.userhost == BOTOP
|
||||
for listener in plugin.listeners:
|
||||
try:
|
||||
plugin.listeners[listener](self,channel,nick,message)
|
||||
except:
|
||||
print("On listener `{}`:".format(listener))
|
||||
traceback.print_exc()
|
||||
try:
|
||||
for listener in plugin.listeners:
|
||||
try:
|
||||
plugin.listeners[listener](self,channel,nick,message)
|
||||
except:
|
||||
print("On listener `{}`:".format(listener))
|
||||
traceback.print_exc()
|
||||
except:
|
||||
print("KERNAL PANIC")
|
||||
traceback.print_exc()
|
||||
if not message.startswith(self.prefix): return
|
||||
args = message[len(self.prefix):].split(" ")
|
||||
cmd = args.pop(0).lower()
|
||||
|
|
Loading…
Reference in New Issue