]>
Commit | Line | Data |
---|---|---|
db75daab JR |
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 | ||
28d7d32f JR |
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 | ||
5c6c0839 | 15 | class modlib(object): |
67e04ca5 | 16 | # default (global) access levels |
1743224e JR |
17 | MANAGER = 100 |
18 | ADMIN = 90 | |
19 | STAFF = 80 | |
db75daab JR |
20 | AUTHED = 0 |
21 | ANYONE = -1 | |
22 | ||
67e04ca5 JR |
23 | # (channel) access levels |
24 | OWNER = -10 | |
25 | MASTER = -8 #master is {-8,-9} | |
26 | OP = -5 #op is {-5,-6,-7} | |
27 | VOICE = -4 | |
28 | KNOWN = -3 | |
29 | PUBLIC = -2 #anyone (use glevel to control auth-needed) | |
30 | ||
5c6c0839 | 31 | def __init__(self, name): |
d1ea05b0 JR |
32 | self.hooks = {} |
33 | self.parent = None | |
34 | ||
5c6c0839 JR |
35 | self.name = name |
36 | ||
37 | def modstart(self, parent): | |
38 | self.parent = parent | |
39 | for cmd, func in self.hooks.iteritems(): | |
40 | self.parent.hook(cmd, func) | |
d1ea05b0 JR |
41 | def modstop(self, parent): |
42 | for cmd, func in self.hooks.iteritems(): | |
43 | self.parent.unhook(cmd, func) | |
5c6c0839 | 44 | |
67e04ca5 | 45 | def hook(self, cmd, needchan=True, glevel=ANYONE, clevel=PUBLIC): |
5c6c0839 | 46 | def realhook(func): |
67e04ca5 JR |
47 | func.needchan = needchan |
48 | func.reqglevel = glevel | |
49 | func.reqclevel = clevel | |
50 | ||
5c6c0839 JR |
51 | self.hooks[cmd] = func |
52 | if self.parent is not None: | |
53 | self.parent.hook(cmd, func) | |
54 | return func | |
55 | return realhook |