Take a name param in modules.py._catch

This commit is contained in:
jesopo 2018-12-02 09:18:24 +00:00
parent da81b20c01
commit 389366ce5d

View file

@ -1,7 +1,7 @@
from src import ModuleManager, utils from src import ModuleManager, utils
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def _catch(self, func): def _catch(self, name, func):
try: try:
func() func()
except ModuleManager.ModuleNotFoundException: except ModuleManager.ModuleNotFoundException:
@ -24,7 +24,7 @@ class Module(ModuleManager.BaseModule):
if name in self.bot.modules.modules: if name in self.bot.modules.modules:
raise utils.EventError("Module '%s' is already loaded" % name) raise utils.EventError("Module '%s' is already loaded" % name)
self._catch(lambda: self.bot.modules.load_module(self.bot, name)) self._catch(name, lambda: self.bot.modules.load_module(self.bot, name))
event["stdout"].write("Loaded '%s'" % name) event["stdout"].write("Loaded '%s'" % name)
@utils.hook("received.command.unloadmodule", min_args=1) @utils.hook("received.command.unloadmodule", min_args=1)
@ -38,7 +38,7 @@ class Module(ModuleManager.BaseModule):
if not name in self.bot.modules.modules: if not name in self.bot.modules.modules:
raise utils.EventError("Module '%s' isn't loaded" % name) raise utils.EventError("Module '%s' isn't loaded" % name)
self._catch(lambda: self.bot.modules.unload_module(name)) self._catch(name, lambda: self.bot.modules.unload_module(name))
event["stdout"].write("Unloaded '%s'" % name) event["stdout"].write("Unloaded '%s'" % name)
def _reload(self, name): def _reload(self, name):
@ -54,7 +54,7 @@ class Module(ModuleManager.BaseModule):
""" """
name = event["args_split"][0].lower() name = event["args_split"][0].lower()
self._catch(lambda: _reload(name)) self._catch(name, lambda: _reload(name))
event["stdout"].write("Reloaded '%s'" % name) event["stdout"].write("Reloaded '%s'" % name)
@utils.hook("received.command.reloadallmodules") @utils.hook("received.command.reloadallmodules")