summaryrefslogtreecommitdiff
path: root/src/plugin.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-09-23 17:43:01 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-09-23 17:43:01 +0200
commite3b933445fe4b18af6ec462fc40da5f482e447a0 (patch)
tree7f5c4060cd913d53000e22f269efce603e323cdc /src/plugin.py
parentf34d3172a11190ebfd8030deb5771a55fdb57476 (diff)
downloadpoezio-e3b933445fe4b18af6ec462fc40da5f482e447a0.tar.gz
poezio-e3b933445fe4b18af6ec462fc40da5f482e447a0.tar.bz2
poezio-e3b933445fe4b18af6ec462fc40da5f482e447a0.tar.xz
poezio-e3b933445fe4b18af6ec462fc40da5f482e447a0.zip
[teisenbe] first attempt at a plugin system.
Diffstat (limited to 'src/plugin.py')
-rw-r--r--src/plugin.py33
1 files changed, 33 insertions, 0 deletions
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()