]>
jfr.im git - erebus.git/blob - modlib.py
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
16 # default (global) access levels
23 # (channel) access levels
29 PUBLIC
= 0 #anyone (use glevel to control auth-needed)
32 WRONGARGS
= "Wrong number of arguments."
34 def __init__(self
, name
):
42 def modstart(self
, parent
):
44 for cmd
, func
in self
.hooks
.iteritems():
45 self
.parent
.hook(cmd
, func
)
46 for num
, func
in self
.numhooks
.iteritems():
47 self
.parent
.hooknum(num
, func
)
48 for chan
, func
in self
.chanhooks
.iteritems():
49 self
.parent
.hookchan(chan
, func
)
51 def modstop(self
, parent
):
52 for cmd
, func
in self
.hooks
.iteritems():
53 self
.parent
.unhook(cmd
, func
)
54 for num
, func
in self
.numhooks
.iteritems():
55 self
.parent
.unhooknum(num
, func
)
56 for chan
, func
in self
.chanhooks
.iteritems():
57 self
.parent
.unhookchan(chan
, func
)
60 def hooknum(self
, num
):
62 self
.numhooks
[num
] = func
63 if self
.parent
is not None:
64 self
.parent
.hooknum(num
, func
)
68 def hookchan(self
, chan
, glevel
=ANYONE
, clevel
=PUBLIC
):
70 self
.chanhooks
[chan
] = func
71 if self
.parent
is not None:
72 self
.parent
.hookchan(chan
, func
)
76 def hook(self
, cmd
, needchan
=True, glevel
=ANYONE
, clevel
=PUBLIC
):
78 func
.needchan
= needchan
79 func
.reqglevel
= glevel
80 func
.reqclevel
= clevel
82 self
.hooks
[cmd
] = func
83 if self
.parent
is not None:
84 self
.parent
.hook(cmd
, func
)
88 def argsEQ(self
, num
):
90 def checkargs(bot
, user
, chan
, realtarget
, *args
):
92 return func(bot
, user
, chan
, realtarget
, *args
)
94 bot
.msg(user
, self
.WRONGARGS
)
98 def argsGE(self
, num
):
100 def checkargs(bot
, user
, chan
, realtarget
, *args
):
102 return func(bot
, user
, chan
, realtarget
, *args
)
104 bot
.msg(user
, self
.WRONGARGS
)