| @@ -75,6 +75,12 @@ class _ResourceManager(object): | |||||
| def _load_resource(self, name, path, klass): | def _load_resource(self, name, path, klass): | ||||
| """Instantiate a resource class and add it to the dictionary.""" | """Instantiate a resource class and add it to the dictionary.""" | ||||
| res_type = self._resource_name[:-1] # e.g. "command" or "task" | res_type = self._resource_name[:-1] # e.g. "command" or "task" | ||||
| if hasattr(klass, "name"): | |||||
| res_config = getattr(self.bot.config, self._resource_name) | |||||
| if getattr(klass, "name") in res_config.get("disable", []): | |||||
| log = "Skipping disabled {0} {1}" | |||||
| self.logger.debug(log.format(res_type, getattr(klass, "name"))) | |||||
| return | |||||
| try: | try: | ||||
| resource = klass(self.bot) # Create instance of resource | resource = klass(self.bot) # Create instance of resource | ||||
| except Exception: | except Exception: | ||||
| @@ -113,6 +119,8 @@ class _ResourceManager(object): | |||||
| def _load_directory(self, dir): | def _load_directory(self, dir): | ||||
| """Load all valid resources in a given directory.""" | """Load all valid resources in a given directory.""" | ||||
| self.logger.debug("Loading directory {0}".format(dir)) | self.logger.debug("Loading directory {0}".format(dir)) | ||||
| res_config = getattr(self.bot.config, self._resource_name) | |||||
| disabled = res_config.get("disable", []) | |||||
| processed = [] | processed = [] | ||||
| for name in listdir(dir): | for name in listdir(dir): | ||||
| if not name.endswith(".py") and not name.endswith(".pyc"): | if not name.endswith(".py") and not name.endswith(".pyc"): | ||||
| @@ -120,6 +128,10 @@ class _ResourceManager(object): | |||||
| if name.startswith("_") or name.startswith("."): | if name.startswith("_") or name.startswith("."): | ||||
| continue | continue | ||||
| modname = sub("\.pyc?$", "", name) # Remove extension | modname = sub("\.pyc?$", "", name) # Remove extension | ||||
| if modname in disabled: | |||||
| log = "Skipping disabled module {0}".format(modname) | |||||
| self.logger.debug(log) | |||||
| continue | |||||
| if modname not in processed: | if modname not in processed: | ||||
| self._load_module(modname, dir) | self._load_module(modname, dir) | ||||
| processed.append(modname) | processed.append(modname) | ||||
| @@ -136,7 +148,11 @@ class _ResourceManager(object): | |||||
| self._resources.clear() | self._resources.clear() | ||||
| builtin_dir = path.join(path.dirname(__file__), name) | builtin_dir = path.join(path.dirname(__file__), name) | ||||
| plugins_dir = path.join(self.bot.config.root_dir, name) | plugins_dir = path.join(self.bot.config.root_dir, name) | ||||
| self._load_directory(builtin_dir) # Built-in resources | |||||
| if getattr(self.bot.config, name).get("disable") is True: | |||||
| log = "Skipping disabled builtins directory {0}" | |||||
| self.logger.debug(log.format(builtin_dir)) | |||||
| else: | |||||
| self._load_directory(builtin_dir) # Built-in resources | |||||
| self._load_directory(plugins_dir) # Custom resources, aka plugins | self._load_directory(plugins_dir) # Custom resources, aka plugins | ||||
| msg = "Loaded {0} {1}: {2}" | msg = "Loaded {0} {1}: {2}" | ||||