update modules.py to use command spec (and not docstrings)

This commit is contained in:
jesopo 2020-02-07 10:46:33 +00:00
parent a19f6304c5
commit 39db6dea55

View file

@ -42,14 +42,12 @@ class Module(ModuleManager.BaseModule):
% (event["user"].nickname, module.name, loaded_at, event_calls, % (event["user"].nickname, module.name, loaded_at, event_calls,
event_str)) event_str))
@utils.hook("received.command.loadmodule", min_args=1) @utils.hook("received.command.loadmodule")
@utils.kwarg("help", "Load a module")
@utils.kwarg("permission", "loadmodule")
@utils.spec("!<name>wordlower")
def load(self, event): def load(self, event):
""" name = event["spec"][0]
:help: Load a module
:usage: <module name>
:permission: load-module
"""
name = event["args_split"][0].lower()
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)
definition = self._catch(name, definition = self._catch(name,
@ -58,14 +56,12 @@ class Module(ModuleManager.BaseModule):
self._catch(name, lambda: self.bot.modules.load_module(self.bot, definition)) self._catch(name, lambda: self.bot.modules.load_module(self.bot, definition))
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")
@utils.kwarg("help", "Unload a module")
@utils.kwarg("permission", "unloadmodule")
@utils.spec("!<name>wordlower")
def unload(self, event): def unload(self, event):
""" name = event["spec"][0]
:help: Unload a module
:usage: <module name>
:permission: unload-module
"""
name = event["args_split"][0].lower()
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)
@ -77,24 +73,19 @@ class Module(ModuleManager.BaseModule):
definition = self._catch(name, definition = self._catch(name,
lambda: self.bot.modules.find_module(name)) lambda: self.bot.modules.find_module(name))
self.bot.modules.load_module(self.bot, definition) self.bot.modules.load_module(self.bot, definition)
@utils.hook("received.command.reloadmodule", min_args=1) @utils.hook("received.command.reloadmodule")
@utils.kwarg("help", "Reload a module")
@utils.kwarg("permission", "reloadmodule")
@utils.spec("!<name>wordlower")
def reload(self, event): def reload(self, event):
""" name = event["spec"][0]
:help: Reload a module
:usage: <module name>
:permission: reload-module
"""
name = event["args_split"][0].lower()
self._catch(name, lambda: self._reload(name)) self._catch(name, lambda: self._reload(name))
event["stdout"].write("Reloaded '%s'" % name) event["stdout"].write("Reloaded '%s'" % name)
@utils.hook("received.command.reloadallmodules") @utils.hook("received.command.reloadallmodules")
@utils.kwarg("help", "Reload all modules")
@utils.kwarg("permission", "reloadallmodules")
def reload_all(self, event): def reload_all(self, event):
"""
:help: Reload all modules
:permission: reload-all-modules
"""
result = self.bot.try_reload_modules() result = self.bot.try_reload_modules()
if result.success: if result.success:
event["stdout"].write(result.message) event["stdout"].write(result.message)