blob: e8386d16a97abd20fcc6ec044b066c65b3c75765 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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()
|