This commit is contained in:
Elián Hanisch 2010-04-03 23:48:54 -03:00
parent 8e05e8748a
commit ca60ba5aa2
2 changed files with 54 additions and 60 deletions

View File

@ -408,40 +408,33 @@ class Bantracker(callbacks.Plugin):
#self.log.debug("SQL return: %q", data) #self.log.debug("SQL return: %q", data)
return data return data
def requestComment(self, irc, channel, ban, type=None): def requestComment(self, irc, channel, ban):
if not ban or not self.registryValue('request', channel): if not ban or not self.registryValue('request', channel) \
return or nickMatch(ban.who, self.registryValue('request.ignore', channel)):
# check if we should request a comment
if nickMatch(ban.who, self.registryValue('request.ignore', channel=channel)):
return return
# check the type of the action taken # check the type of the action taken
mask = ban.mask mask = ban.mask
if not type:
type = guessBanType(mask) type = guessBanType(mask)
if type == 'quiet': if type == 'quiet':
mask = mask[1:] mask = mask[1:]
# check if type is enabled # check if type is enabled
if type not in self.registryValue('request.type', channel=channel): if type not in self.registryValue('request.type', channel):
return return
# send msg
prefix = conf.supybot.reply.whenAddressedBy.chars()[0] # prefix char for commands prefix = conf.supybot.reply.whenAddressedBy.chars()[0] # prefix char for commands
# check to who send the request # check to who send the request
try: try:
op = ircutils.nickFromHostmask(ban.who) nick = ircutils.nickFromHostmask(ban.who)
except: except:
op = ban.who nick = ban.who
if nickMatch(op, self.registryValue('request.forward', channel=channel)): if nickMatch(nick, self.registryValue('request.forward', channel)):
channels = self.registryValue('request.forward.channels', channel=channel)
s = "Please somebody comment on the %s of %s in %s done by %s, use:"\ s = "Please somebody comment on the %s of %s in %s done by %s, use:"\
" %scomment %s <comment>" %(type, mask, channel, op, prefix, ban.id) " %scomment %s <comment>" %(type, mask, channel, nick, prefix, ban.id)
for chan in channels: self._sendForward(irc, s, channel)
msg = ircmsgs.notice(chan, s) else:
irc.queueMsg(msg)
return
# send to op # send to op
s = "Please comment on the %s of %s in %s, use: %scomment %s <comment>" \ s = "Please comment on the %s of %s in %s, use: %scomment %s <comment>" \
%(type, mask, channel, prefix, ban.id) %(type, mask, channel, prefix, ban.id)
irc.reply(s, to=op, private=True) irc.reply(s, to=nick, private=True)
def reviewBans(self, irc=None): def reviewBans(self, irc=None):
reviewTime = int(self.registryValue('request.review') * 86400) reviewTime = int(self.registryValue('request.review') * 86400)
@ -450,85 +443,85 @@ class Bantracker(callbacks.Plugin):
return return
now = time.mktime(time.gmtime()) now = time.mktime(time.gmtime())
lastreview = self.pendingReviews.time lastreview = self.pendingReviews.time
self.pendingReviews.time = now # update last time reviewed
if not lastreview: if not lastreview:
# initialize last time reviewed timestamp # initialize last time reviewed timestamp
lastreview = now - reviewTime lastreview = now - reviewTime
bansite = self.registryValue('bansite')
for channel, bans in self.bans.iteritems(): for channel, bans in self.bans.iteritems():
if not self.registryValue('enabled', channel=channel) \ if not self.registryValue('enabled', channel) \
or not self.registryValue('request', channel=channel): or not self.registryValue('request', channel):
continue continue
ignore = self.registryValue('request.ignore', channel=channel)
forward = self.registryValue('request.forward', channel=channel)
fchannels = self.registryValue('request.forward.channels', channel=channel)
for ban in bans: for ban in bans:
type = guessBanType(ban.mask) if guessBanType(ban.mask) in ('quiet', 'removal'):
if type in ('quiet', 'removal'):
# skip mutes and kicks # skip mutes and kicks
continue continue
banAge = now - ban.when banAge = now - ban.when
reviewWindow = lastreview - ban.when reviewWindow = lastreview - ban.when
self.log.debug(' channel %s ban %s by %s (%s/%s/%s %s)', channel, ban.mask, #self.log.debug('review ban: %s ban %s by %s (%s/%s/%s %s)', channel, ban.mask,
ban.who, reviewWindow, reviewTime, banAge, reviewTime-reviewWindow) # ban.who, reviewWindow, reviewTime, banAge, reviewTime - reviewWindow)
if reviewWindow <= reviewTime < banAge: if reviewWindow <= reviewTime < banAge:
# ban is old enough, and inside the "review window" # ban is old enough, and inside the "review window"
try: try:
# ban.who should be a user hostmask # ban.who should be a user hostmask
op = ircutils.nickFromHostmask(ban.who) nick = ircutils.nickFromHostmask(ban.who)
host = ircutils.hostFromHostmask(ban.who) host = ircutils.hostFromHostmask(ban.who)
except: except:
if ircutils.isNick(ban.who, strictRfc=True): if ircutils.isNick(ban.who, strictRfc=True):
# ok, op's nick, use it # ok, op's nick, use it
op = ban.who nick = ban.who
host = None host = None
else: else:
# probably a ban restored by IRC server in a netsplit # probably a ban restored by IRC server in a netsplit
# XXX see if something can be done about this # XXX see if something can be done about this
continue continue
if nickMatch(op, ignore): if nickMatch(nick, self.registryValue('request.ignore', channel)):
# in the ignore list # in the ignore list
continue continue
if not ban.id: if not ban.id:
ban.id = self.get_banId(ban.mask, channel) ban.id = self.get_banId(ban.mask, channel)
if nickMatch(op, forward): if nickMatch(nick, self.registryValue('request.forward', channel)):
if not irc:
continue
s = "Hi, please somebody review the ban '%s' set by %s on %s in"\ s = "Hi, please somebody review the ban '%s' set by %s on %s in"\
" %s, link: %s/bans.cgi?log=%s" %(ban.mask, op, ban.ascwhen, channel, " %s, link: %s/bans.cgi?log=%s" %(ban.mask, nick, ban.ascwhen, channel,
bansite, ban.id) self.registryValue('bansite'), ban.id)
for chan in fchannels: self._sendForward(irc, s, channel)
msg = ircmsgs.notice(chan, s)
irc.queueMsg(msg)
else: else:
s = "Hi, please review the ban '%s' that you set on %s in %s, link:"\ s = "Hi, please review the ban '%s' that you set on %s in %s, link:"\
" %s/bans.cgi?log=%s" %(ban.mask, ban.ascwhen, channel, bansite, ban.id) " %s/bans.cgi?log=%s" %(ban.mask, ban.ascwhen, channel,
msg = ircmsgs.privmsg(op, s) self.registryValue('bansite'), ban.id)
if host not in self.pendingReviews: msg = ircmsgs.privmsg(nick, s)
self.pendingReviews[host] = [] if host in self.pendingReviews:
self.pendingReviews[host].append((op, msg)) self.pendingReviews[host].append((nick, msg))
else:
self.pendingReviews[host] = [(nick, msg)]
elif banAge < reviewTime: elif banAge < reviewTime:
# since we made sure bans are sorted by time, the bans left are more recent # since we made sure bans are sorted by time, the bans left are more recent
break break
self.pendingReviews.time = now # update last time reviewed
def _sendForward(self, irc, s, channel=None):
if not irc:
return
for chan in self.registryValue('request.forward.channels', channel=channel):
msg = ircmsgs.notice(chan, s)
irc.queueMsg(msg)
def _sendReviews(self, irc, msg): def _sendReviews(self, irc, msg):
host = ircutils.hostFromHostmask(msg.prefix) host = ircutils.hostFromHostmask(msg.prefix)
if host in self.pendingReviews: if host in self.pendingReviews:
op = msg.nick for nick, m in self.pendingReviews[host]:
for nick, msg in self.pendingReviews[host]: if msg.nick != nick and not irc.isChannel(nick): # I'm a bit extra careful here
if op != nick and not irc.isChannel(nick): # be extra careful
# correct nick in msg # correct nick in msg
msg = ircmsgs.privmsg(op, msg.args[1]) m = ircmsgs.privmsg(msg.nick, m.args[1])
irc.queueMsg(msg) irc.queueMsg(m)
del self.pendingReviews[host] del self.pendingReviews[host]
# check if we have any reviews by nick to send # check if we have any reviews by nick to send
if None in self.pendingReviews: if None in self.pendingReviews:
op = msg.nick
L = self.pendingReviews[None] L = self.pendingReviews[None]
for i, v in enumerate(L): for i, v in enumerate(L):
nick, msg = v nick, m = v
if nickMatch(op, nick): if ircutils.strEqual(msg.nick, nick):
irc.queueMsg(msg) irc.queueMsg(m)
del L[i] del L[i]
if not L: if not L:
del self.pendingReviews[None] del self.pendingReviews[None]

View File

@ -157,6 +157,7 @@ class BantrackerTestCase(ChannelPluginTestCase):
# don't ask again # don't ask again
cb.reviewBans() cb.reviewBans()
self.assertFalse(cb.pendingReviews) self.assertFalse(cb.pendingReviews)
# test again with two ops
self.feedBan('asd2!*@*') self.feedBan('asd2!*@*')
self.irc.takeMsg() self.irc.takeMsg()
self.feedBan('qwe!*@*', prefix='otherop!user@home.net') self.feedBan('qwe!*@*', prefix='otherop!user@home.net')