From b8225fd5073b0ec3367c378ead07a9d6d03c7c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eli=C3=A1n=20Hanisch?= Date: Thu, 5 Jul 2012 19:24:49 -0300 Subject: [PATCH] fix previous commit, Ban objects are never going to be of other type than ban and quiet. --- Bantracker/plugin.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Bantracker/plugin.py b/Bantracker/plugin.py index dcf5e0b..a3dd479 100644 --- a/Bantracker/plugin.py +++ b/Bantracker/plugin.py @@ -245,16 +245,7 @@ class Ban(object): @property def type(self): - mask = self.mask - if mask[0] == '%': - return 'quiet' - elif ircutils.isUserHostmask(mask) or mask.endswith('(realname)'): - if not ('*' in mask or '?' in mask or '$' in mask): - # XXX hack over hack, we are supposing these are marks as normal - # bans aren't usually set to exact match, while marks are. - return 'mark' - return 'ban' - return 'removal' + return guessBanType(self.mask) def serialize(self): id = self.id @@ -274,6 +265,18 @@ class Ban(object): self.ascwhen = time.asctime(time.gmtime(self.when)) +def guessBanType(mask): + if mask[0] == '%': + return 'quiet' + elif ircutils.isUserHostmask(mask) or mask.endswith('(realname)'): + if not ('*' in mask or '?' in mask or '$' in mask): + # XXX hack over hack, we are supposing these are marks as normal + # bans aren't usually set to exact match, while marks are. + return 'mark' + return 'ban' + return 'removal' + + class ReviewStore(dict): def __init__(self, filename): self.filename = conf.supybot.directories.data.dirize(filename) @@ -1455,6 +1458,11 @@ class Bantracker(callbacks.Plugin): return mask, channel, removal = L[0] + type = guessBanType(mask) + if type not in ('ban', 'quiet'): + irc.reply("Id %s is a %s, only bans or quiets can be autoremoved." % (id, type)) + return + if removal: irc.reply("Ban '%s' was already removed in %s." % (mask, channel)) return @@ -1469,10 +1477,6 @@ class Bantracker(callbacks.Plugin): irc.reply("Ban '%s' isn't active in %s." % (mask, channel)) return - if ban.type not in ('ban', 'quiet'): - irc.reply("Id %s is a %s, only bans or quiets can be autoremoved." \ - % (id, ban.type)) - return self.managedBans.add(BanRemoval(ban, seconds)) irc.replySuccess()