AttackProtector: Add support for temporary kbans.

master
Valentin Lorentz 2013-05-18 16:41:06 +02:00
parent 1ef8c6ba2a
commit 2976ead4fc
3 changed files with 37 additions and 3 deletions

View File

@ -66,9 +66,15 @@ class Punishment(registry.String):
def set(self, s):
if s not in ('ban', 'kick', 'kban') and not s.startswith('mode+') and \
not s.startswith('mode-') and not s.startswith('umode-') and \
not s.startswith('umode+') and not s.startswith('command '):
not s.startswith('umode+') and \
not s.startswith('command ') and not s.startswith('kban+'):
self.error()
return
if s.startswith('kban+'):
try:
int(s[5:])
except ValueError:
self.error()
self.setValue(s)
Punishment = internationalizeDocstring(Punishment)

View File

@ -30,6 +30,7 @@
import re
import time
import functools
import supybot.conf as conf
import supybot.utils as utils
@ -37,6 +38,7 @@ import supybot.ircdb as ircdb
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircmsgs as ircmsgs
import supybot.schedule as schedule
import supybot.registry as registry
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
@ -205,11 +207,18 @@ class AttackProtector(callbacks.Plugin):
elif punishment == 'ban':
msg = ircmsgs.ban(channel, banmask)
irc.queueMsg(msg)
elif punishment == 'kban':
elif punishment.startswith('kban'):
msg = ircmsgs.ban(channel, banmask)
irc.queueMsg(msg)
msg = ircmsgs.kick(channel, nick, reason)
irc.queueMsg(msg)
if punishment.startswith('kban+'):
time = int(punishment[5:])
unban = functools.partial(irc.queueMsg,
ircmsgs.unban(channel, banmask))
schedule.addEvent(unban, time)
elif punishment.startswith('mode'):
msg = ircmsgs.mode(channel, punishment[len('mode'):])
irc.queueMsg(msg)

View File

@ -30,7 +30,9 @@
import time
from supybot.test import *
import supybot.conf as conf
import supybot.ircdb as ircdb
import supybot.schedule as schedule
class AttackProtectorTestCase(ChannelPluginTestCase):
plugins = ('AttackProtector', 'Config', 'Utilities', 'User')
@ -201,11 +203,28 @@ class AttackProtectorTestCase(ChannelPluginTestCase):
msg = ircmsgs.privmsg(self.channel, 'Hi, this is a flood',
prefix=self.prefix)
self.irc.feedMsg(msg)
self.assertNotError('config plugin.AttackProtector.message.punishment '
self.assertNotError('config plugins.AttackProtector.message.punishment '
'umode+b')
return self._getIfAnswerIsEqual(ircmsgs.IrcMsg(prefix="", command="MODE",
args=(self.channel, mode, self.nick)))
def testKban(self):
with conf.supybot.plugins.AttackProtector.message.punishment.context(
'kban+1'):
for i in range(1, 11):
msg = ircmsgs.privmsg(self.channel, 'Hi, this is a flood',
prefix=self.prefix)
self.irc.feedMsg(msg)
m = self.irc.takeMsg()
self.assertEqual(m.command, 'MODE')
m = self.irc.takeMsg()
self.assertEqual(m.command, 'KICK')
self.assertEqual(self.irc.takeMsg(), None)
schedule.run()
time.sleep(2)
m = self.irc.takeMsg()
self.assertEqual(m.command, 'MODE')
#################################
# 'Kicked' tests
def testKbanAfterKicks(self):