removed try: except: block

This commit is contained in:
Elián Hanisch 2010-04-03 00:26:20 -03:00
parent fd4516f077
commit dda5154237

View File

@ -212,6 +212,7 @@ class PersistentCache(dict):
return (host, nick, command, channel, text) return (host, nick, command, channel, text)
class Bantracker(callbacks.Plugin): class Bantracker(callbacks.Plugin):
"""Plugin to manage bans. """Plugin to manage bans.
See '@list Bantracker' and '@help <command>' for commands""" See '@list Bantracker' and '@help <command>' for commands"""
@ -443,72 +444,66 @@ class Bantracker(callbacks.Plugin):
irc.reply(s, to=op, private=True) irc.reply(s, to=op, private=True)
def reviewBans(self): def reviewBans(self):
try: self.log.debug('Checking for bans that need review ...')
self.log.debug('Checking for bans that need review ...') now = time.mktime(time.gmtime())
now = time.mktime(time.gmtime()) lastreview = self.pendingReviews.time
lastreview = self.pendingReviews.time bansite = self.registryValue('bansite')
bansite = self.registryValue('bansite') if not lastreview:
if not lastreview: # initialize last time reviewed timestamp
# initialize last time reviewed timestamp lastreview = now - self.registryValue('request.review')
lastreview = now - self.registryValue('request.review') for channel, bans in self.bans.iteritems():
for channel, bans in self.bans.iteritems(): reviewAfterTime = int(self.registryValue('request.review', channel=channel) * 86400)
reviewAfterTime = int(self.registryValue('request.review', channel=channel) * 86400) if not reviewAfterTime:
if not reviewAfterTime: # time is zero, do nothing
# time is zero, do nothing 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:
type = guessBanType(ban.mask)
if type in ('quiet', 'removal'):
# skip mutes and kicks
continue continue
ignore = self.registryValue('request.ignore', channel=channel) banTime = now - ban.when
forward = self.registryValue('request.forward', channel=channel) reviewTime = lastreview - ban.when
fchannels = self.registryValue('request.forward.channels', channel=channel) self.log.debug(' channel %s ban %s (%s %s %s)', channel, str(ban), reviewTime,
for ban in bans: reviewAfterTime, reviewAfterTime-reviewTime)
type = guessBanType(ban.mask) if reviewTime <= reviewAfterTime < banTime:
if type in ('quiet', 'removal'): # ban is old enough, and inside the "review window"
# skip mutes and kicks try:
# ban.who should be a user hostmask
op = ircutils.nickFromHostmask(ban.who)
host = ircutils.hostFromHostmask(ban.who)
except:
# probably a ban restored by IRC server in a netsplit
# XXX see if something can be done about this
continue continue
banTime = now - ban.when if nickMatch(op, ignore):
reviewTime = lastreview - ban.when # in the ignore list
self.log.debug(' channel %s ban %s (%s %s %s)', channel, str(ban), reviewTime, continue
reviewAfterTime, reviewAfterTime-reviewTime) self.log.debug(' adding ban to the pending review list ...')
if reviewTime <= reviewAfterTime < banTime: if not ban.id:
# ban is old enough, and inside the "review window" ban.id = self.get_banId(ban.mask, channel)
try: if nickMatch(op, forward):
# ban.who should be a user hostmask msgs = []
op = ircutils.nickFromHostmask(ban.who) s = "Hi, please somebody review the ban '%s' set by %s on %s in"\
host = ircutils.hostFromHostmask(ban.who) " %s, link: %s/bans.cgi?log=%s" %(ban.mask, op, ban.ascwhen, channel,
except: bansite, ban.id)
# probably a ban restored by IRC server in a netsplit for chan in fchannels:
# XXX see if something can be done about this msgs.append(ircmsgs.notice(chan, s))
continue # FIXME forwards should be sent now, not later.
if nickMatch(op, ignore): else:
# in the ignore list s = "Hi, please review the ban '%s' that you set on %s in %s, link:"\
continue " %s/bans.cgi?log=%s" %(ban.mask, ban.ascwhen, channel, bansite, ban.id)
self.log.debug(' adding ban to the pending review list ...') msgs = [ircmsgs.privmsg(op, s)]
if not ban.id: if host not in self.pendingReviews:
ban.id = self.get_banId(ban.mask, channel) self.pendingReviews[host] = []
if nickMatch(op, forward): for msg in msgs:
msgs = [] self.pendingReviews[host].append((op, msg))
s = "Hi, please somebody review the ban '%s' set by %s on %s in"\ elif banTime < reviewAfterTime:
" %s, link: %s/bans.cgi?log=%s" %(ban.mask, op, ban.ascwhen, channel, # since we made sure bans are sorted by time, the bans left are more recent
bansite, ban.id) break
for chan in fchannels: self.pendingReviews.time = now # update last time reviewed
msgs.append(ircmsgs.notice(chan, s))
# FIXME forwards should be sent now, not later.
else:
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)
msgs = [ircmsgs.privmsg(op, s)]
if host not in self.pendingReviews:
self.pendingReviews[host] = []
for msg in msgs:
self.pendingReviews[host].append((op, msg))
elif banTime < reviewAfterTime:
# since we made sure bans are sorted by time, the bans left are more recent
break
self.pendingReviews.time = now # update last time reviewed
except Exception, e:
# I need to catch exceptions as they are silenced
import traceback
self.log.error('Except: %s' %e)
self.log.error(traceback.format_exc())
def _sendReviews(self, irc, msg): def _sendReviews(self, irc, msg):
host = ircutils.hostFromHostmask(msg.prefix) host = ircutils.hostFromHostmask(msg.prefix)