Browse Source

Improve config file command/task exclusion logic.

tags/v0.3
Ben Kurtovic 8 years ago
parent
commit
f9b646b0b8
3 changed files with 21 additions and 7 deletions
  1. +1
    -0
      CHANGELOG
  2. +7
    -0
      docs/customizing.rst
  3. +13
    -7
      earwigbot/managers.py

+ 1
- 0
CHANGELOG View File

@@ -1,6 +1,7 @@
v0.3 (unreleased):

- Copyvio detector: improved sentence splitting algorithm.
- Improved config file command/task exclusion logic.
- IRC > !cidr: Added; new command for calculating range blocks.
- IRC > !notes: Improved help and added aliases.
- IRC > !remind: Added !remind all. Fixed multithreading efficiency issues.


+ 7
- 0
docs/customizing.rst View File

@@ -174,6 +174,13 @@ The bot has a wide selection of built-in commands and plugins to act as sample
code and/or to give ideas. Start with test_, and then check out chanops_ and
afc_status_ for some more complicated scripts.

By default, the bot loads every built-in and custom command available. You can
disable *all* built-in commands with the config entry
:py:attr:`config.commands["disable"]` set to ``True``, or a subset of commands
by setting it to a list of command class names or module names. If using the
former method, you can specifically enable certain built-in commands with
:py:attr:`config.commands["enable"]` set to a list of command module names.

Custom bot tasks
----------------



+ 13
- 7
earwigbot/managers.py View File

@@ -72,14 +72,21 @@ class _ResourceManager(object):
for resource in self._resources.itervalues():
yield resource

def _is_disabled(self, name):
"""Check whether a resource should be disabled."""
conf = getattr(self.bot.config, self._resource_name)
disabled = conf.get("disable", [])
enabled = conf.get("enable", [])
return name not in enabled and (disabled is True or name in disabled)

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", []):
classname = getattr(klass, "name")
if self._is_disabled(name) and self._is_disabled(classname):
log = "Skipping disabled {0} {1}"
self.logger.debug(log.format(res_type, getattr(klass, "name")))
self.logger.debug(log.format(res_type, classname))
return
try:
resource = klass(self.bot) # Create instance of resource
@@ -119,8 +126,6 @@ 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"):
@@ -128,7 +133,7 @@ class _ResourceManager(object):
if name.startswith("_") or name.startswith("."):
continue
modname = sub("\.pyc?$", "", name) # Remove extension
if modname in disabled:
if self._is_disabled(modname):
log = "Skipping disabled module {0}".format(modname)
self.logger.debug(log)
processed.append(modname)
@@ -162,7 +167,8 @@ class _ResourceManager(object):
self._unload_resources()
builtin_dir = path.join(path.dirname(__file__), name)
plugins_dir = path.join(self.bot.config.root_dir, name)
if getattr(self.bot.config, name).get("disable") is True:
conf = getattr(self.bot.config, name)
if conf.get("disable") is True and not conf.get("enable"):
log = "Skipping disabled builtins directory: {0}"
self.logger.debug(log.format(builtin_dir))
else:


Loading…
Cancel
Save