Add -m/-M args to ./start.py that call command_line on individual modules

This commit is contained in:
jesopo 2019-02-24 10:43:46 +00:00
parent f3f6102dbc
commit faa305f2e8
2 changed files with 14 additions and 1 deletions

View file

@ -39,6 +39,10 @@ class BaseModule(object):
pass pass
def unload(self): def unload(self):
pass pass
def command_line(self, args: str):
pass
class LoadedModule(object): class LoadedModule(object):
def __init__(self, def __init__(self,
name: str, name: str,
@ -157,7 +161,7 @@ class ModuleManager(object):
return LoadedModule(name, module_object, context, import_name) return LoadedModule(name, module_object, context, import_name)
def load_module(self, bot: "IRCBot.Bot", name: str): def load_module(self, bot: "IRCBot.Bot", name: str) -> LoadedModule:
try: try:
loaded_module = self._load_module(bot, name) loaded_module = self._load_module(bot, name)
except ModuleWarning as warning: except ModuleWarning as warning:
@ -174,6 +178,7 @@ class ModuleManager(object):
loaded_module.name]: loaded_module.name]:
self.load_module(bot, requirement_name) self.load_module(bot, requirement_name)
self.log.debug("Module '%s' loaded", [loaded_module.name]) self.log.debug("Module '%s' loaded", [loaded_module.name])
return loaded_module
def load_modules(self, bot: "IRCBot.Bot", whitelist: typing.List[str]=[], def load_modules(self, bot: "IRCBot.Bot", whitelist: typing.List[str]=[],
blacklist: typing.List[str]=[]): blacklist: typing.List[str]=[]):

View file

@ -31,6 +31,9 @@ arg_parser.add_argument("--log-level", "-L")
arg_parser.add_argument("--version", "-v", action="store_true") arg_parser.add_argument("--version", "-v", action="store_true")
arg_parser.add_argument("--module", "-m")
arg_parser.add_argument("--module-args", "-M")
args = arg_parser.parse_args() args = arg_parser.parse_args()
if args.version: if args.version:
@ -60,6 +63,11 @@ modules = modules = ModuleManager.ModuleManager(events, exports, timers, config,
bot = IRCBot.Bot(directory, args, cache, config, database, events, bot = IRCBot.Bot(directory, args, cache, config, database, events,
exports, log, modules, timers) exports, log, modules, timers)
if args.module:
module = modules.load_module(bot, args.module)
module.module.command_line(args.module_args)
sys.exit(0)
whitelist = bot.get_setting("module-whitelist", []) whitelist = bot.get_setting("module-whitelist", [])
blacklist = bot.get_setting("module-blacklist", []) blacklist = bot.get_setting("module-blacklist", [])