Merge lp:~m4v/ubuntu-bots/bugfixes into lp:ubuntu-bots

Proposed by m4v
Status: Merged
Merged at revision: 161
Proposed branch: lp:~m4v/ubuntu-bots/bugfixes
Merge into: lp:ubuntu-bots
Diff against target: 197 lines (+91/-10)
2 files modified
Bantracker/config.py (+30/-3)
Bantracker/plugin.py (+61/-7)
To merge this branch: bzr merge lp:~m4v/ubuntu-bots/bugfixes
Reviewer Review Type Date Requested Status
Terence Simpson Approve
Review via email: mp+22316@code.launchpad.net

Description of the change

-implements feature described in bug #521516
-some minor fixes (a typo and syntax error)
-catch except on realname bans

To post a comment you must log in.
Revision history for this message
Terence Simpson (tsimpson) wrote :

Approved for merge

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Bantracker/config.py'
--- Bantracker/config.py 2009-10-12 18:26:35 +0000
+++ Bantracker/config.py 2010-03-28 05:00:41 +0000
@@ -15,13 +15,40 @@
15import supybot.conf as conf15import supybot.conf as conf
16import supybot.registry as registry16import supybot.registry as registry
1717
18class ValidTypes(registry.OnlySomeStrings):
19 """Invalid type, valid types are: 'removal', 'ban' or 'quiet'."""
20 validStrings = ('removal', 'ban', 'quiet')
21
22class SpaceSeparatedListOfTypes(registry.SpaceSeparatedListOf):
23 Value = ValidTypes
24
25
18def configure(advanced):26def configure(advanced):
19 conf.registerPlugin('Bantracker', True)27 conf.registerPlugin('Bantracker', True)
2028
21Bantracker = conf.registerPlugin('Bantracker')29Bantracker = conf.registerPlugin('Bantracker')
22conf.registerChannelValue(conf.supybot.plugins.Bantracker, 'enabled',30conf.registerChannelValue(Bantracker, 'enabled',
23 registry.Boolean(False, """Enable the bantracker"""))31 registry.Boolean(False, """Enable the bantracker"""))
24conf.registerGlobalValue(conf.supybot.plugins.Bantracker, 'database',32conf.registerGlobalValue(Bantracker, 'database',
25 registry.String('', "Filename of the bans database", private=True))33 registry.String('', "Filename of the bans database", private=True))
26conf.registerGlobalValue(conf.supybot.plugins.Bantracker, 'bansite',34conf.registerGlobalValue(Bantracker, 'bansite',
27 registry.String('', "Web site for the bantracker, without the 'bans.cgi' appended", private=True))35 registry.String('', "Web site for the bantracker, without the 'bans.cgi' appended", private=True))
36
37conf.registerGroup(Bantracker, 'commentRequest')
38conf.registerChannelValue(Bantracker.commentRequest, 'type',
39 SpaceSeparatedListOfTypes(['removal', 'ban', 'quiet'],
40 "List of events for which the bot should request a comment."))
41conf.registerChannelValue(Bantracker.commentRequest, 'ignore',
42 registry.SpaceSeparatedListOfStrings([],
43 "List of nicks for which the bot won't request to comment a ban/quiet/removal."\
44 " Is case insensible and wildcards * ? are accepted."))
45conf.registerChannelValue(Bantracker.commentRequest, 'forward',
46 registry.SpaceSeparatedListOfStrings([],
47 "List of nicks for which the bot will forward the request to"\
48 " the channels/nicks defined in forwards.channels option."\
49 " Is case insensible and wildcards * ? are accepted."))
50conf.registerChannelValue(Bantracker.commentRequest.forward, 'channels',
51 registry.SpaceSeparatedListOfStrings([],
52 "List of channels/nicks to forward the request if the op that set the ban/quiet"\
53 " is in the forward list."))
54
2855
=== modified file 'Bantracker/plugin.py'
--- Bantracker/plugin.py 2010-03-28 03:34:17 +0000
+++ Bantracker/plugin.py 2010-03-28 05:00:41 +0000
@@ -48,6 +48,7 @@
48import supybot.ircmsgs as ircmsgs48import supybot.ircmsgs as ircmsgs
49import supybot.conf as conf49import supybot.conf as conf
50import supybot.ircdb as ircdb50import supybot.ircdb as ircdb
51from fnmatch import fnmatch
51import sqlite52import sqlite
52import pytz53import pytz
53import cPickle54import cPickle
@@ -91,6 +92,16 @@
91 pattern = pattern[1:]92 pattern = pattern[1:]
92 return ircutils.hostmaskPatternEqual(pattern, hostmask)93 return ircutils.hostmaskPatternEqual(pattern, hostmask)
9394
95def nickMatch(nick, pattern):
96 """Checks if a given nick matches a pattern or in a list of patterns."""
97 if isinstance(pattern, str):
98 pattern = [pattern]
99 nick = nick.lower()
100 for s in pattern:
101 if fnmatch(nick, s.lower()):
102 return True
103 return False
104
94def dequeue(parent, irc):105def dequeue(parent, irc):
95 global queue106 global queue
96 queue.dequeue(parent, irc)107 queue.dequeue(parent, irc)
@@ -116,8 +127,9 @@
116class Ban(object):127class Ban(object):
117 """Hold my bans"""128 """Hold my bans"""
118 def __init__(self, args=None, **kwargs):129 def __init__(self, args=None, **kwargs):
119 object.__init__(self)130 self.id = None
120 if args:131 if args:
132 # in most ircd: args = (nick, channel, mask, who, when)
121 self.mask = args[2]133 self.mask = args[2]
122 self.who = args[3]134 self.who = args[3]
123 self.when = float(args[4])135 self.when = float(args[4])
@@ -125,6 +137,8 @@
125 self.mask = kwargs['mask']137 self.mask = kwargs['mask']
126 self.who = kwargs['who']138 self.who = kwargs['who']
127 self.when = float(kwargs['when'])139 self.when = float(kwargs['when'])
140 if 'id' in kwargs:
141 self.id = kwargs['id']
128 self.ascwhen = time.asctime(time.gmtime(self.when))142 self.ascwhen = time.asctime(time.gmtime(self.when))
129143
130 def __tuple__(self):144 def __tuple__(self):
@@ -207,7 +221,7 @@
207 mask = "%s!%s@%s" % (nick, msg.args[2].lower(), msg.args[3].lower())221 mask = "%s!%s@%s" % (nick, msg.args[2].lower(), msg.args[3].lower())
208 self.nicks[nick] = mask222 self.nicks[nick] = mask
209 if nick in self.replies:223 if nick in self.replies:
210 f = getattr(self, "real_%s" % self.replies[nick][0])224 f = getattr(self, "%s_real" % self.replies[nick][0])
211 args = self.replies[nick][1]225 args = self.replies[nick][1]
212 del self.replies[nick]226 del self.replies[nick]
213 kwargs={'from_reply': True, 'reply': "%s!%s@%s" % (msg.args[1], msg.args[2], msg.args[3])}227 kwargs={'from_reply': True, 'reply': "%s!%s@%s" % (msg.args[1], msg.args[2], msg.args[3])}
@@ -220,7 +234,7 @@
220 if not nick in self.nicks:234 if not nick in self.nicks:
221 self.nicks[nick] = mask235 self.nicks[nick] = mask
222 if nick in self.replies:236 if nick in self.replies:
223 f = getattr(self, "real_%s" % self.replies[nick][0])237 f = getattr(self, "%s_real" % self.replies[nick][0])
224 args = self.replies[nick][1]238 args = self.replies[nick][1]
225 del self.replies[nick]239 del self.replies[nick]
226 kwargs={'from_reply': True, 'reply': "%s!%s@%s" % (msg.args[1], msg.args[2], msg.args[3])}240 kwargs={'from_reply': True, 'reply': "%s!%s@%s" % (msg.args[1], msg.args[2], msg.args[3])}
@@ -234,7 +248,7 @@
234 """/whowas faild"""248 """/whowas faild"""
235 nick = msg.args[1].lower()249 nick = msg.args[1].lower()
236 if nick in self.replies:250 if nick in self.replies:
237 f = getattr(self, "real_%s" % self.replies[nick][0])251 f = getattr(self, "%s_real" % self.replies[nick][0])
238 args = self.replies[nick][1]252 args = self.replies[nick][1]
239 del self.replies[nick]253 del self.replies[nick]
240 kwargs = {'from_reply': True, 'reply': None}254 kwargs = {'from_reply': True, 'reply': None}
@@ -324,6 +338,40 @@
324 self.db.commit()338 self.db.commit()
325 return data339 return data
326340
341 def requestComment(self, irc, channel, ban, type=None):
342 # check if we should request a comment
343 if nickMatch(ban.who, self.registryValue('commentRequest.ignore', channel=channel)):
344 return
345 # check the type of the action taken
346 mask = ban.mask
347 if not type:
348 if mask[0] == '%':
349 type = 'quiet'
350 mask = mask[1:]
351 elif ircutils.isUserHostmask(mask) or mask.endswith('(realname)'):
352 type = 'ban'
353 else:
354 type = 'removal'
355 # check if type is enabled
356 if type not in self.registryValue('commentRequest.type', channel=channel):
357 return
358 # send msg
359 prefix = conf.supybot.reply.whenAddressedBy.chars()[0] # prefix char for commands
360 # check to who send the request
361 if nickMatch(ban.who, self.registryValue('commentRequest.forward', channel=channel)):
362 channels = self.registryValue('commentRequest.forward.channels', channel=channel)
363 if channels:
364 s = "Please somebody comment on the %s of %s in %s done by %s, use:"\
365 " %scomment %s <comment>" %(type, mask, channel, ban.who, prefix, ban.id)
366 for chan in channels:
367 msg = ircmsgs.notice(chan, s)
368 irc.queueMsg(msg)
369 return
370 # send to op
371 s = "Please comment on the %s of %s in %s, use: %scomment %s <comment>" \
372 %(type, mask, channel, prefix, ban.id)
373 irc.reply(s, to=ban.who, private=True)
374
327 def doLog(self, irc, channel, s):375 def doLog(self, irc, channel, s):
328 if not self.registryValue('enabled', channel):376 if not self.registryValue('enabled', channel):
329 return377 return
@@ -350,7 +398,9 @@
350 self.db_run("INSERT INTO comments (ban_id, who, comment, time) values(%s,%s,%s,%s)", (id, nick, extra_comment, n))398 self.db_run("INSERT INTO comments (ban_id, who, comment, time) values(%s,%s,%s,%s)", (id, nick, extra_comment, n))
351 if channel not in self.bans:399 if channel not in self.bans:
352 self.bans[channel] = []400 self.bans[channel] = []
353 self.bans[channel].append(Ban(mask=target, who=nick, when=time.mktime(time.gmtime())))401 ban = Ban(mask=target, who=nick, when=time.mktime(time.gmtime()), id=id)
402 self.bans[channel].append(ban)
403 self.requestComment(irc, channel, ban)
354 return id404 return id
355405
356 def doUnban(self, irc, channel, nick, mask):406 def doUnban(self, irc, channel, nick, mask):
@@ -448,7 +498,7 @@
448 ' '.join(msg.args[2:])))498 ' '.join(msg.args[2:])))
449 modes = ircutils.separateModes(msg.args[1:])499 modes = ircutils.separateModes(msg.args[1:])
450 for param in modes:500 for param in modes:
451 realname = ''501 realname = ''
452 mode = param[0]502 mode = param[0]
453 mask = ''503 mask = ''
454 comment=None504 comment=None
@@ -473,7 +523,11 @@
473 self.lastStates[irc] = irc.state.copy()523 self.lastStates[irc] = irc.state.copy()
474 if mask[0] == '%':524 if mask[0] == '%':
475 mask = mask[1:]525 mask = mask[1:]
476 (nick, ident, host) = ircutils.splitHostmask(mask)526 try:
527 (nick, ident, host) = ircutils.splitHostmask(mask)
528 except AssertionError:
529 # not a hostmask
530 return None
477 channel = None531 channel = None
478 chan = None532 chan = None
479 if mask[0] not in ('*', '?'): # Nick ban533 if mask[0] not in ('*', '?'): # Nick ban

Subscribers

People subscribed via source and target branches