AttackProtector: Fix scheduling.

master
Valentin Lorentz 2013-05-18 18:27:12 +02:00
parent f2af02e494
commit 63ab52e429
2 changed files with 13 additions and 6 deletions

View File

@ -209,10 +209,10 @@ class AttackProtector(callbacks.Plugin):
irc.queueMsg(msg)
if punishment.startswith('ban+'):
time = int(punishment[4:])
delay = int(punishment[4:])
unban = functools.partial(irc.queueMsg,
ircmsgs.unban(channel, banmask))
schedule.addEvent(unban, time)
schedule.addEvent(unban, delay + time.time())
elif punishment.startswith('kban'):
msg = ircmsgs.ban(channel, banmask)
@ -221,10 +221,10 @@ class AttackProtector(callbacks.Plugin):
irc.queueMsg(msg)
if punishment.startswith('kban+'):
time = int(punishment[5:])
delay = int(punishment[5:])
unban = functools.partial(irc.queueMsg,
ircmsgs.unban(channel, banmask))
schedule.addEvent(unban, time)
schedule.addEvent(unban, delay + time.time())
elif punishment.startswith('mode'):
msg = ircmsgs.mode(channel, punishment[len('mode'):])

View File

@ -209,8 +209,11 @@ class AttackProtectorTestCase(ChannelPluginTestCase):
args=(self.channel, mode, self.nick)))
def testKban(self):
def run_schedule():
while schedule.schedule.schedule:
schedule.run()
with conf.supybot.plugins.AttackProtector.message.punishment.context(
'kban+1'):
'kban+2'):
for i in range(1, 11):
msg = ircmsgs.privmsg(self.channel, 'Hi, this is a flood',
prefix=self.prefix)
@ -220,10 +223,14 @@ class AttackProtectorTestCase(ChannelPluginTestCase):
m = self.irc.takeMsg()
self.assertEqual(m.command, 'KICK')
self.assertEqual(self.irc.takeMsg(), None)
schedule.run()
threading.Thread(target=run_schedule).start()
self.assertEqual(self.irc.takeMsg(), None)
time.sleep(1)
self.assertEqual(self.irc.takeMsg(), None)
time.sleep(2)
m = self.irc.takeMsg()
self.assertEqual(m.command, 'MODE')
schedule.schedule.schedule = False
#################################
# 'Kicked' tests