reviewAfterTime is now stored in seconds, but when setting the value the unit

is days.

This saves the user for calculating how many seconds a day is, while allowing
me to set times of some seconds for automatic testing.
This commit is contained in:
Elián Hanisch 2010-03-30 17:13:00 -03:00
parent e60e72a620
commit 3dd2f09769
2 changed files with 21 additions and 2 deletions

View File

@ -23,6 +23,20 @@ class SpaceSeparatedListOfTypes(registry.SpaceSeparatedListOf):
Value = ValidTypes
# This registry translates days to seconds
# storing seconds instead of days is more convenient for testing
class DaysToSeconds(registry.Integer):
"""Value must be an integer and not higher than 100"""
def set(self, s):
try:
n = int(s)
if n > 100:
raise ValueError
self.setValue(n*84600)
except ValueError:
self.error()
def configure(advanced):
conf.registerPlugin('Bantracker', True)
@ -57,4 +71,6 @@ conf.registerChannelValue(Bantracker.commentRequest.forward, 'channels',
conf.registerGlobalValue(Bantracker, 'reviewTime',
registry.Integer(0, "", ))
conf.registerGlobalValue(Bantracker, 'reviewAfterTime',
registry.Integer(2, "", ))
DaysToSeconds(7*84600,
"Days after which the bot will request for review a ban. NOTE: the number of days is"
" stored in seconds, but when configuring it the time unit is in days."))

View File

@ -383,10 +383,13 @@ class Bantracker(callbacks.Plugin):
def reviewBans(self):
try:
reviewAfterTime = self.registryValue('reviewAfterTime')
if not reviewAfterTime:
# time is zero, do nothing
return
self.log.debug('Checking for bans that need review ...')
now = time.mktime(time.gmtime())
lastreview = self.registryValue('reviewTime')
reviewAfterTime = self.registryValue('reviewAfterTime') * 60 # time in mins
if not lastreview:
# initialize last time reviewed timestamp
lastreview = now - reviewAfterTime