Beispiel #1
0
 async def load(self, *, module_name: str):
     """Loads a module
     
     Example: load mod"""
     module = module_name.strip()
     if "modules." not in module:
         module = "modules." + module
     try:
         self._load_module(module)
     except ModuleNotFoundError:
         await self.bot.say("The module could not be found.")
     except ModuleLoadError as e:
         log.exception(e)
         traceback.print_exc()
         await self.bot.say('There was an issue loading the module. Check'
                            " your console or logs for more information.")
     except Exception as e:
         log.exception(e)
         traceback.print_exc()
         await self.bot.say("Module was found and possibly loaded but "
                            "something went wrong. Check your console "
                            "or logs for more information.")
     else:
         set_module(module, True)
         await self.disable_commands()
         await self.bot.say("The module has been loaded")
Beispiel #2
0
    async def _reload(self, *, module_name: str):
        """Reloads a module

        Example: reload audio"""
        module = module_name.strip()
        if "modules." not in module:
            module = "modules." + module

        try:
            self._unload_module(module, reloading=True)
        except:
            pass

        try:
            self._load_module(module)
        except ModuleNotFoundError:
            await self.bot.say("That module cannot be found.")
        except NoSetupError:
            await self.bot.say("That module does not have a setup function.")
        except ModuleLoadError as e:
            log.exception(e)
            traceback.print_exc()
            await self.bot.say("That module could not be loaded. Check your"
                               " console or logs for more information.")
        else:
            set_module(module, True)
            await self.disable_commands()
            await self.bot.say("The module has been reloaded.")
Beispiel #3
0
 async def uninstall(self, ctx, repo_name, module):
     """Uninstalls a module"""
     if repo_name not in self.repos:
         await self.bot.say("That repo doesn't exist.")
         return
     if module not in self.repos[repo_name]:
         await self.bot.say("That module isn't available from that repo.")
         return
     set_module("modules." + module, False)
     self.repos[repo_name][module]['INSTALLED'] = False
     self.save_repos()
     os.remove(os.path.join("modules", module + ".py"))
     owner = self.bot.get_module('Owner')
     await owner.unload.callback(owner, module_name=module)
     await self.bot.say("Module successfully uninstalled.")
Beispiel #4
0
 async def _install(self, ctx, repo_name: str, module: str):
     """Installs specified module"""
     if repo_name not in self.repos:
         await self.bot.say("That repo doesn't exist.")
         return
     if module not in self.repos[repo_name]:
         await self.bot.say("That module isn't available from that repo.")
         return
     data = self.get_info_data(repo_name, module)
     try:
         install_module = await self.install(repo_name,
                                             module,
                                             notify_reqs=True)
     except RequirementFail:
         await self.bot.say("That module has requirements that I could not "
                            "install. Check the console for more "
                            "informations.")
         return
     if data is not None:
         install_msg = data.get("INSTALL_MSG", None)
         if install_msg:
             await self.bot.say(install_msg[:2000])
     if install_module:
         await self.bot.say("Installation completed. Load it now? (yes/no)")
         answer = await self.bot.wait_for_message(timeout=15,
                                                  author=ctx.message.author)
         if answer is None:
             await self.bot.say("Ok then, you can load it with"
                                " `{}load {}`".format(ctx.prefix, module))
         elif answer.content.lower().strip() == "yes":
             set_module("modules." + module, True)
             owner = self.bot.get_module('Owner')
             await owner.load.callback(owner, module_name=module)
         else:
             await self.bot.say("Ok then, you can load it with"
                                " `{}load {}`".format(ctx.prefix, module))
     elif install_module is False:
         await self.bot.say("Invalid module. Installation aborted.")
     else:
         await self.bot.say(
             "That module doesn't exist. Use module list to see"
             " the full list.")
Beispiel #5
0
 async def unload_all(self):
     """Unloads all modules"""
     modules = self._list_modules()
     still_loaded = []
     for module in modules:
         set_module(module, False)
         try:
             self._unload_module(module)
         except OwnerUnloadWithoutReloadError:
             pass
         except ModuleUnloadError as e:
             log.exception(e)
             traceback.print_exc()
             still_loaded.append(module)
     if still_loaded:
         still_loaded = ", ".join(still_loaded)
         await self.bot.say("I was unable to unload some modules:"
                            "{}".format(still_loaded))
     else:
         await self.bot.say("All modules are now unloaded.")
Beispiel #6
0
 async def unload(self, *, module_name: str):
     """Unloads a module
     
     Example: unload mod"""
     module = module_name.strip()
     if "modules" not in module:
         module = "modules." + module
     if not self._does_modulefile_exist(module):
         await self.bot.say("Thet module file doesn't exist. I will not"
                            "turn off autoloading at start just in case"
                            "this isn't supposed to happen.")
     else:
         set_module(module, True)
     try: # No matter what we should try to unload it
         self._unload_module(module)
     except OwnerUnloadWithoutReloadError:
         await self.bot.say("I cannot allow you to unload the Owner Plugin"
                            " unless you are in the process of reloading.")
     except ModuleUnloadError as e:
         log.exception(e)
         traceback.print_exc()
         await self.bot.say('Unable to safely unload that module.')
     else:
         await self.bot.say("The module has been unloaded.")