]>
Commit | Line | Data |
---|---|---|
1 | # Erebus IRC bot - Author: John Runyon | |
2 | # module helper functions, see modules/modtest.py for usage | |
3 | # This file is released into the public domain; see http://unlicense.org/ | |
4 | ||
5 | class error(object): | |
6 | def __init__(self, desc): | |
7 | self.errormsg = desc | |
8 | def __nonzero__(self): | |
9 | return False #object will test to False | |
10 | def __repr__(self): | |
11 | return '<modlib.error %r>' % self.errormsg | |
12 | def __str__(self): | |
13 | return self.errormsg | |
14 | ||
15 | class modlib(object): | |
16 | #access levels | |
17 | MANAGER = 3 | |
18 | ADMIN = 2 | |
19 | STAFF = 1 | |
20 | AUTHED = 0 | |
21 | ANYONE = -1 | |
22 | ||
23 | def __init__(self, name): | |
24 | self.hooks = {} | |
25 | self.parent = None | |
26 | ||
27 | self.name = name | |
28 | ||
29 | def modstart(self, parent): | |
30 | self.parent = parent | |
31 | for cmd, func in self.hooks.iteritems(): | |
32 | self.parent.hook(cmd, func) | |
33 | def modstop(self, parent): | |
34 | for cmd, func in self.hooks.iteritems(): | |
35 | self.parent.unhook(cmd, func) | |
36 | ||
37 | def hook(self, cmd): | |
38 | def realhook(func): | |
39 | self.hooks[cmd] = func | |
40 | if self.parent is not None: | |
41 | self.parent.hook(cmd, func) | |
42 | return func | |
43 | return realhook |