]> jfr.im git - irc/evilnet/x3.git/blame - src/plugins/__init__.py
Couple of srvx updates.
[irc/evilnet/x3.git] / src / plugins / __init__.py
CommitLineData
1ad8c8df 1import imp
2import os.path
3
4class Plugin(object):
5 def server_link(self, server):
6 pass
7
c9b009fe 8 def new_user(self, user):
9 pass
10
0a585d7e 11 def nick_change(self, user, oldnick):
12 pass
13
9c7f11c2 14 def del_user(self, user, killer, why):
15 pass
16
43b43d56 17 def topic(self, who, chan, old_topic):
18 pass
19
1ad8c8df 20def load_path(path, prefix):
21 mods = []
22
23 for entry in os.listdir(path):
24 if os.path.isfile(os.path.join(path, entry)):
25 if os.path.splitext(entry)[1] != '.py':
26 continue
27
28 if entry.startswith('.') or entry.startswith('__'):
29 continue
30
31 try:
32 args = imp.find_module(os.path.splitext(entry)[0], [path])
33 except ImportError:
34 continue
35
36 if args:
37 mod = imp.load_module(prefix + os.path.splitext(entry)[0], *args)
38 if args[0]:
39 args[0].close()
40 if mod:
41 mods.append(mod)
42
43 if os.path.isdir(os.path.join(path, entry)):
44 mods.extend(load_path(os.path.join(path, entry), prefix + entry + '.'))
45
46 return mods
47
48def load():
49 mods = load_path(os.path.dirname(__file__), 'plugins.')
50 plugins = {}
51
52 # for some reason this returns multiple instances of the same plugin types
53 candidates = Plugin.__subclasses__()
54 for plg in candidates:
30814f13 55 if plg.__name__ not in plugins:
56 plugins[plg.__name__] = plg()
1ad8c8df 57
58 return plugins.values()