don't ignore extra words prefixed to the duration in @comment or @duration

This commit is contained in:
Elián Hanisch 2012-07-27 23:12:35 -03:00
parent 846667faf2
commit d241665208
2 changed files with 7 additions and 2 deletions

View File

@ -113,6 +113,9 @@ def readTimeDelta(s):
digit = string = number = None digit = string = number = None
seconds = 0 seconds = 0
for c in s: for c in s:
if c == ' ':
continue
if c.isdigit(): if c.isdigit():
if string is None: if string is None:
# start # start
@ -132,7 +135,7 @@ def readTimeDelta(s):
else: else:
if digit is None: if digit is None:
# need a number first # need a number first
continue raise ValueError(s)
if digit is True: if digit is True:
digit = False digit = False
# completed a number # completed a number
@ -1544,7 +1547,7 @@ class Bantracker(callbacks.Plugin):
nick = msg.nick nick = msg.nick
duration, banset = None, [] duration, banset = None, []
if kickmsg and ',' in kickmsg: if kickmsg and ',' in kickmsg:
s = kickmsg[kickmsg.rfind(','):] s = kickmsg[kickmsg.rfind(',') + 1:]
try: try:
duration = readTimeDelta(s) duration = readTimeDelta(s)
except ValueError: except ValueError:

View File

@ -136,6 +136,8 @@ class BantrackerTestCase(ChannelPluginTestCase):
self.feedBan('nick', mode='k') self.feedBan('nick', mode='k')
self.assertResponse('comment 2 this is a kick, 2week', self.assertResponse('comment 2 this is a kick, 2week',
'The operation succeeded.') 'The operation succeeded.')
self.assertResponse('comment 1 not a valid, duration 2',
'The operation succeeded.')
def testMultiComment(self): def testMultiComment(self):
self.feedBan('asd!*@*') self.feedBan('asd!*@*')