summaryrefslogtreecommitdiffstats
path: root/bot.py
diff options
context:
space:
mode:
authorSean B. Palmer <http://inamidst.com/sbp/>2008-03-31 16:17:32 +0100
committerSean B. Palmer <http://inamidst.com/sbp/>2008-03-31 16:17:32 +0100
commit286d4a8497621d2f3c0f1f8d66db60b11c87fad5 (patch)
tree23493e843bcb1a1d6b25346a3dfd6290df46d5ba /bot.py
parentfb2cd452e963b8bc048161036903cd82d3b113f0 (diff)
downloadbot-286d4a8497621d2f3c0f1f8d66db60b11c87fad5.tar.gz
bot-286d4a8497621d2f3c0f1f8d66db60b11c87fad5.tar.bz2
bot-286d4a8497621d2f3c0f1f8d66db60b11c87fad5.zip
New "limit" config variable, and some module fixes.
Diffstat (limited to 'bot.py')
-rwxr-xr-xbot.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/bot.py b/bot.py
index ae97d93..37f892c 100755
--- a/bot.py
+++ b/bot.py
@@ -161,9 +161,9 @@ class Phenny(irc.Bot):
return PhennyWrapper(self)
- def input(self, origin, text, bytes, match, event):
+ def input(self, origin, text, bytes, match, event, args):
class CommandInput(unicode):
- def __new__(cls, text, origin, bytes, match, event):
+ def __new__(cls, text, origin, bytes, match, event, args):
s = unicode.__new__(cls, text)
s.sender = origin.sender
s.nick = origin.nick
@@ -172,19 +172,28 @@ class Phenny(irc.Bot):
s.match = match
s.group = match.group
s.groups = match.groups
+ s.args = args
s.admin = origin.nick in self.config.admins
s.owner = origin.nick == self.config.owner
return s
- return CommandInput(text, origin, bytes, match, event)
+ return CommandInput(text, origin, bytes, match, event, args)
def call(self, func, origin, phenny, input):
try: func(phenny, input)
except Exception, e:
self.error(origin)
+ def limit(self, origin, func):
+ if origin.sender and origin.sender.startswith('#'):
+ if hasattr(self.config, 'limit'):
+ limits = self.config.limit.get(origin.sender)
+ if limits and (func.__module__ not in limits):
+ return True
+ return False
+
def dispatch(self, origin, args):
- bytes, event = args[0], args[1]
+ bytes, event, args = args[0], args[1], args[2:]
text = decode(bytes)
for priority in ('high', 'medium', 'low'):
@@ -192,15 +201,17 @@ class Phenny(irc.Bot):
for regexp, funcs in items:
for func in funcs:
if event != func.event: continue
-
+
match = regexp.match(text)
if match:
+ if self.limit(origin, func): continue
+
phenny = self.wrapped(origin, text, match)
- input = self.input(origin, text, bytes, match, event)
+ input = self.input(origin, text, bytes, match, event, args)
if func.thread:
- args = (func, origin, phenny, input)
- t = threading.Thread(target=self.call, args=args)
+ targs = (func, origin, phenny, input)
+ t = threading.Thread(target=self.call, args=targs)
t.start()
else: self.call(func, origin, phenny, input)