Przeglądaj źródła

Support for config options to disable loading default commands/tasks.

tags/v0.1^2
Ben Kurtovic 12 lat temu
rodzic
commit
7e733c39bb
1 zmienionych plików z 17 dodań i 1 usunięć
  1. +17
    -1
      earwigbot/managers.py

+ 17
- 1
earwigbot/managers.py Wyświetl plik

@@ -75,6 +75,12 @@ class _ResourceManager(object):
def _load_resource(self, name, path, klass):
"""Instantiate a resource class and add it to the dictionary."""
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:
resource = klass(self.bot) # Create instance of resource
except Exception:
@@ -113,6 +119,8 @@ class _ResourceManager(object):
def _load_directory(self, dir):
"""Load all valid resources in a given directory."""
self.logger.debug("Loading directory {0}".format(dir))
res_config = getattr(self.bot.config, self._resource_name)
disabled = res_config.get("disable", [])
processed = []
for name in listdir(dir):
if not name.endswith(".py") and not name.endswith(".pyc"):
@@ -120,6 +128,10 @@ class _ResourceManager(object):
if name.startswith("_") or name.startswith("."):
continue
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:
self._load_module(modname, dir)
processed.append(modname)
@@ -136,7 +148,11 @@ class _ResourceManager(object):
self._resources.clear()
builtin_dir = path.join(path.dirname(__file__), 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

msg = "Loaded {0} {1}: {2}"


Ładowanie…
Anuluj
Zapisz