Browse Source

Improve config file command/task exclusion logic.

tags/v0.3
Ben Kurtovic 9 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): v0.3 (unreleased):


- Copyvio detector: improved sentence splitting algorithm. - Copyvio detector: improved sentence splitting algorithm.
- Improved config file command/task exclusion logic.
- IRC > !cidr: Added; new command for calculating range blocks. - IRC > !cidr: Added; new command for calculating range blocks.
- IRC > !notes: Improved help and added aliases. - IRC > !notes: Improved help and added aliases.
- IRC > !remind: Added !remind all. Fixed multithreading efficiency issues. - 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 code and/or to give ideas. Start with test_, and then check out chanops_ and
afc_status_ for some more complicated scripts. 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 Custom bot tasks
---------------- ----------------




+ 13
- 7
earwigbot/managers.py View File

@@ -72,14 +72,21 @@ class _ResourceManager(object):
for resource in self._resources.itervalues(): for resource in self._resources.itervalues():
yield resource 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): 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"): 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}" log = "Skipping disabled {0} {1}"
self.logger.debug(log.format(res_type, getattr(klass, "name")))
self.logger.debug(log.format(res_type, classname))
return return
try: try:
resource = klass(self.bot) # Create instance of resource resource = klass(self.bot) # Create instance of resource
@@ -119,8 +126,6 @@ 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"):
@@ -128,7 +133,7 @@ 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:
if self._is_disabled(modname):
log = "Skipping disabled module {0}".format(modname) log = "Skipping disabled module {0}".format(modname)
self.logger.debug(log) self.logger.debug(log)
processed.append(modname) processed.append(modname)
@@ -162,7 +167,8 @@ class _ResourceManager(object):
self._unload_resources() self._unload_resources()
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)
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}" log = "Skipping disabled builtins directory: {0}"
self.logger.debug(log.format(builtin_dir)) self.logger.debug(log.format(builtin_dir))
else: else:


Loading…
Cancel
Save