def reset_modules(update, _): for i in list(Loader.loaded()): Loader.unload(i) reply(update, 'All modules unloaded. Loading modules.') success = [] for mod in Permissions.modules(): try: Loader.load(mod) success.append(mod) except ModuleNotFoundError as err: reply(update, str(err)) logging.warning(str(err)) if len(success) > 0: msg = 'Successfully loaded:' + djoin(success) reply(update, msg)
def load_module(update, args, *, cmd='load'): mod = '' try: mod = args[0] Loader.load(mod) reply(update, mod + ' successfully loaded') return True except (AssertionError, IndexError) as e: msg = 'Usage: /module ' + cmd + ' <module>' unloaded = [ i for i in Permissions.modules() if i not in Loader.loaded() ] msg += '\nUnloaded modules:' + djoin(unloaded) reply(update, msg) return False except ModuleNotFoundError as err: logging.error('Failed to load module "' + mod + '" with error: ' + str(err)) reply(update, 'Failed to load module.') raise
def main(_): setup_logs() # For security if not is_in_container(): logging.error('Error: Not executing from container!') sys.exit(1) # Telegram API setup updater = None with open('token.priv') as f: updater = Updater(f.read().strip(), use_context=True) dp = updater.dispatcher # Create handler registration Permissions.setup(permisions_f) invoke_extra_args = { 'mmj_lic': ro_path, 'pubkey': ro_path, 'shopping': rw_path + '/shopping/', 'log': log_file } Loader.setup(dp, module_ordered_path, invoke_extra_args, unknown, error) # Load modules for mod in Permissions.modules(): try: Loader.load(mod) except ModuleNotFoundError as err: logging.warning(str(err)) # Start the Bot logging.info('Initiating polling.') updater.start_polling() # Block until you press Ctrl-C or the process receives SIGINT, SIGTERM or # SIGABRT. This should be used most of the time, since start_polling() is # non-blocking and will stop the bot gracefully. updater.idle()
def list_module(update, *_): reply(update, 'Modules:' + djoin(Permissions.modules()))