summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsand <daniel@spatof.org>2013-05-30 18:33:48 (GMT)
committer sand <daniel@spatof.org>2013-05-30 18:35:44 (GMT)
commitd6bf2c5a3ea696a5673f53096775993dec9d9ac2 (patch)
tree7c539c655505698fc803daf75efe9061f6a9a716
parent15bf0979b5f91ad34266554ec3babeadb92b36e0 (diff)
plugin configuration
-rw-r--r--pinolo/bot.py6
-rw-r--r--pinolo/plugins/__init__.py3
-rw-r--r--pinolo/plugins/markov.py15
-rw-r--r--pinolo/plugins/quotes2.py7
-rw-r--r--sample_config.coil7
5 files changed, 23 insertions, 15 deletions
diff --git a/pinolo/bot.py b/pinolo/bot.py
index 54563e4..6eb31ae 100644
--- a/pinolo/bot.py
+++ b/pinolo/bot.py
@@ -280,7 +280,11 @@ class Bot(SignalDispatcher):
for plugin_name, plugin_class in pinolo.plugins.registry:
log.info("Activating plugin %s" % plugin_name)
- p_obj = plugin_class(self)
+ if plugin_name in self.config["plugins"]:
+ plugin_config = self.config["plugins"][plugin_name]
+ else:
+ plugin_config = {}
+ p_obj = plugin_class(self, plugin_config)
p_obj.activate()
self.plugins.append(p_obj)
COMMAND_ALIASES.update(p_obj.COMMAND_ALIASES.items())
diff --git a/pinolo/plugins/__init__.py b/pinolo/plugins/__init__.py
index eb14a59..3e1fae5 100644
--- a/pinolo/plugins/__init__.py
+++ b/pinolo/plugins/__init__.py
@@ -40,10 +40,11 @@ class Plugin(object):
if name != "Plugin":
registry.append((name, cls))
- def __init__(self, bot, enabled=True):
+ def __init__(self, bot, config, enabled=True):
"""Initialize the plugin instance with a pointer to the bot object"""
self.bot = bot
+ self.config = config
self.enabled = enabled
def activate(self):
diff --git a/pinolo/plugins/markov.py b/pinolo/plugins/markov.py
index d7c8d88..07871b2 100644
--- a/pinolo/plugins/markov.py
+++ b/pinolo/plugins/markov.py
@@ -164,16 +164,11 @@ class MarkovBrain(object):
class MarkovPlugin(Plugin):
-
- def __init__(self, bot):
- super(MarkovPlugin, self).__init__(bot)
- self.db_file = os.path.join(self.bot.config['datadir'], "markov.pickle")
+ def activate(self):
+ self.db_file = os.path.join(self.config.get("@root.datadir"),
+ "markov.pickle")
self.markov = MarkovBrain(self.db_file)
self._counter = 0
- self.verbosity = self.bot.config.get("markov_verbosity", 97)
- self.save_every = self.bot.config.get("markov_save_every", 50)
-
- def activate(self):
self.markov.load()
def deactivate(self):
@@ -195,11 +190,11 @@ class MarkovPlugin(Plugin):
else:
self.markov.learn(event.text)
self._counter += 1
- if self._counter >= self.save_every:
+ if self._counter >= self.config.get("save_every", 50):
self._counter = 0
self.markov.save()
- if random.randint(0, 100) >= self.verbosity:
+ if random.randint(0, 100) >= self.config.get("verbosity", 95):
reply = self.markov.say(event.text)
if reply:
event.reply(reply, prefix=False)
diff --git a/pinolo/plugins/quotes2.py b/pinolo/plugins/quotes2.py
index e53b6e2..1f10734 100644
--- a/pinolo/plugins/quotes2.py
+++ b/pinolo/plugins/quotes2.py
@@ -60,9 +60,10 @@ class QuotesPlugin(Plugin):
's': 'search',
}
- def __init__(self, bot):
- super(QuotesPlugin, self).__init__(bot)
- self.db_path = os.path.join(self.bot.config['datadir'], "whoosh")
+ def __init__(self, bot, config, enabled=True):
+ super(QuotesPlugin, self).__init__(bot, config, enabled)
+ self.db_path = os.path.join(self.config.get("@root.datadir"),
+ "whoosh")
self.to_be_indexed = False
self.init_whoosh()
diff --git a/sample_config.coil b/sample_config.coil
index 53fa79f..a7daedb 100644
--- a/sample_config.coil
+++ b/sample_config.coil
@@ -21,4 +21,11 @@ servers: {
host: "irc.example.com"
channels: ["#pinolandia"]
}
+}
+
+plugins: {
+ markov: {
+ verbosity: 95
+ save_every: 50
+ }
} \ No newline at end of file