]>
jfr.im git - erebus.git/blob - modlib.py
d2fe492b4c2af97fa0581e9586db3e9d05689b98
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/
6 def __init__(self
, desc
):
9 return False #object will test to False
11 return '<modlib.error %r>' % self
.errormsg
13 return str(self
.errormsg
)
16 # default (global) access levels
24 # (channel) access levels
30 PUBLIC
= 0 #anyone (use glevel to control auth-needed)
33 WRONGARGS
= "Wrong number of arguments."
35 def __init__(self
, name
):
43 def modstart(self
, parent
):
45 for cmd
, func
in self
.hooks
.iteritems():
46 self
.parent
.hook(cmd
, func
)
47 for num
, func
in self
.numhooks
.iteritems():
48 self
.parent
.hooknum(num
, func
)
49 for chan
, func
in self
.chanhooks
.iteritems():
50 self
.parent
.hookchan(chan
, func
)
52 def modstop(self
, parent
):
53 for cmd
, func
in self
.hooks
.iteritems():
54 self
.parent
.unhook(cmd
, func
)
55 for num
, func
in self
.numhooks
.iteritems():
56 self
.parent
.unhooknum(num
, func
)
57 for chan
, func
in self
.chanhooks
.iteritems():
58 self
.parent
.unhookchan(chan
, func
)
61 def hooknum(self
, num
):
63 self
.numhooks
[num
] = func
64 if self
.parent
is not None:
65 self
.parent
.hooknum(num
, func
)
69 def hookchan(self
, chan
, glevel
=ANYONE
, clevel
=PUBLIC
):
71 self
.chanhooks
[chan
] = func
72 if self
.parent
is not None:
73 self
.parent
.hookchan(chan
, func
)
77 def hook(self
, cmd
, needchan
=True, glevel
=ANYONE
, clevel
=PUBLIC
):
79 func
.needchan
= needchan
80 func
.reqglevel
= glevel
81 func
.reqclevel
= clevel
83 self
.hooks
[cmd
] = func
84 if self
.parent
is not None:
85 self
.parent
.hook(cmd
, func
)
89 def argsEQ(self
, num
):
91 def checkargs(bot
, user
, chan
, realtarget
, *args
):
93 return func(bot
, user
, chan
, realtarget
, *args
)
95 bot
.msg(user
, self
.WRONGARGS
)
99 def argsGE(self
, num
):
101 def checkargs(bot
, user
, chan
, realtarget
, *args
):
103 return func(bot
, user
, chan
, realtarget
, *args
)
105 bot
.msg(user
, self
.WRONGARGS
)