From e3b933445fe4b18af6ec462fc40da5f482e447a0 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Fri, 23 Sep 2011 17:43:01 +0200 Subject: [teisenbe] first attempt at a plugin system. --- src/plugin.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/plugin.py (limited to 'src/plugin.py') diff --git a/src/plugin.py b/src/plugin.py new file mode 100644 index 00000000..e8386d16 --- /dev/null +++ b/src/plugin.py @@ -0,0 +1,33 @@ +import inspect + +class BasePlugin(object): + """ + Class that all plugins derive from. Any methods beginning with command_ + are interpreted as a command and beginning with on_ are interpreted as + event handlers + """ + + def __init__(self, core): + self.core = core + for k, v in inspect.getmembers(self, inspect.ismethod): + if k.startswith('on_'): + core.xmpp.add_event_handler(k[3:], v) + elif k.startswith('command_'): + command = k[len('command_'):] + core.commands[command] = (v, v.__doc__, None) + self.init() + + def init(self): + pass + + def cleanup(self): + pass + + def unload(self): + for k, v in inspect.getmembers(self, inspect.ismethod): + if k.startswith('on_'): + self.core.xmpp.del_event_handler(k[3:], v) + elif k.startswith('command_'): + command = k[len('command_'):] + del self.core.commands[command] + self.cleanup() -- cgit v1.2.3