modified a bit how mass repeat detection works

This commit is contained in:
Nicolas Coevoet 2014-12-11 18:55:42 +01:00
parent 1f401a897d
commit 006f98dd9d
3 changed files with 39 additions and 35 deletions

View File

@ -37,7 +37,7 @@ import supybot.world as world
# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you're keeping the plugin in CVS or some similar system.
__version__ = "1.0"
__version__ = "1.1"
# XXX Replace this with an appropriate author or supybot.Author instance.
__author__ = supybot.authors.unknown

View File

@ -180,9 +180,9 @@ conf.registerChannelValue(ChanTracker, 'useChanServForQuiets',
# flood detection settings
conf.registerChannelValue(ChanTracker, 'floodPermit',
registry.Integer(-1,"""Number of messages allowed during floodLife, -1 to disable, advice 4"""))
registry.Integer(-1,"""Number of messages allowed during floodLife, -1 to disable"""))
conf.registerChannelValue(ChanTracker, 'floodLife',
registry.PositiveInteger(7,"""Duration of messages's life in flood counter, in seconds, advice 7"""))
registry.PositiveInteger(7,"""Duration of messages's life in flood counter, in seconds"""))
conf.registerChannelValue(ChanTracker, 'floodMode',
registry.String('q',"""mode used by the bot when flood detection is triggered"""))
conf.registerChannelValue(ChanTracker, 'floodDuration',
@ -192,9 +192,9 @@ registry.String('flood detected',"""comment added on mode changes database, empt
# another flood queue, for user with throttled irc client, who copy / paste long text
conf.registerChannelValue(ChanTracker, 'lowFloodPermit',
registry.Integer(-1,"""Number of messages allowed during lowFloodLife, -1 to disable, advice 5"""))
registry.Integer(-1,"""Number of messages allowed during lowFloodLife, -1 to disable"""))
conf.registerChannelValue(ChanTracker, 'lowFloodLife',
registry.Integer(13,"""Duration of messages's life in lowFlood counter, in seconds, advice 13"""))
registry.Integer(13,"""Duration of messages's life in lowFlood counter, in seconds"""))
conf.registerChannelValue(ChanTracker, 'lowFloodMode',
registry.String('q',"""mode used by the bot when low flood detection is triggered"""))
conf.registerChannelValue(ChanTracker, 'lowFloodDuration',
@ -204,10 +204,9 @@ registry.String('low flood detected',"""comment added on mode changes database,
# repeat detection
conf.registerChannelValue(ChanTracker, 'repeatPermit',
registry.Integer(-1,"""Number of repeated text allowed, -1 to disable, note, first message doesn't count,
so if you want to trigger it after 3 repeat, you must set it to 1, advice 4"""))
registry.Integer(-1,"""Number of repeated text allowed, -1 to disable"""))
conf.registerChannelValue(ChanTracker, 'repeatLife',
registry.PositiveInteger(120,"""Duration of messages's life in repeatPermit counter in seconds, advice 120"""))
registry.PositiveInteger(12,"""Duration of messages's life in repeatPermit counter in seconds"""))
conf.registerChannelValue(ChanTracker, 'repeatPercent',
registry.Probability(0.85,"""percent of similarity needed between previous and current message to trigger a repeat count"""))
conf.registerChannelValue(ChanTracker, 'repeatMode',
@ -219,13 +218,13 @@ registry.String('repeat detected',"""comment added on mode changes database, emp
# mass repeat detection
conf.registerChannelValue(ChanTracker, 'massRepeatChars',
registry.PositiveInteger(100,"""number of chars needed to enter massRepeat detection"""))
registry.PositiveInteger(40,"""number of chars needed to enter massRepeat detection"""))
conf.registerChannelValue(ChanTracker, 'massRepeatPermit',
registry.Integer(-1,"""Number of repeated text allowed, -1 to disable, tracks message repetition from various sources on the given channel"""))
conf.registerChannelValue(ChanTracker, 'massRepeatLife',
registry.PositiveInteger(120,"""Duration of messages's life in massRepeat counter, in seconds"""))
registry.PositiveInteger(12,"""Duration of messages's life in massRepeat counter, in seconds"""))
conf.registerChannelValue(ChanTracker, 'massRepeatPercent',
registry.Probability(0.95,"""percentage similarity between previous and current message to trigger a repeat count"""))
registry.Probability(0.85,"""percentage similarity between previous and current message to trigger a repeat count"""))
conf.registerChannelValue(ChanTracker, 'massRepeatMode',
registry.String('b',"""mode used by the bot when repeat detection is triggered"""))
conf.registerChannelValue(ChanTracker, 'massRepeatDuration',
@ -240,9 +239,9 @@ if found string < length setted, it uses the default string compare"""))
# YES IT'S ANNOYING
conf.registerChannelValue(ChanTracker, 'capPermit',
registry.Integer(-1,"""Number of UPPERCASE messages allowed, -1 to disable, advice 3; see capPercent for definition of an UPPERCASE message"""))
registry.Integer(-1,"""Number of UPPERCASE messages allowed, -1 to disable. see capPercent for definition of an UPPERCASE message"""))
conf.registerChannelValue(ChanTracker, 'capLife',
registry.PositiveInteger(120,"""Duration in seconds before messages are removed from count, advice 120"""))
registry.PositiveInteger(30,"""Duration in seconds before messages are removed from count"""))
conf.registerChannelValue(ChanTracker, 'capPercent',
registry.Probability(0.75,"""percentage of uppercase chars in a message to trigger a cap count"""))
conf.registerChannelValue(ChanTracker, 'capMode',
@ -254,7 +253,7 @@ registry.String('capslock detected',"""comment added on mode changes database, e
# hilight
conf.registerChannelValue(ChanTracker, 'hilightPermit',
registry.Integer(-1,"""Number of nick allowed per message, -1 to disable, advice 2 - 3, note : it doesn't care if it's the same nick"""))
registry.Integer(-1,"""Number of nick allowed per message, -1 to disable, note : it doesn't care if it's the same nick"""))
conf.registerChannelValue(ChanTracker, 'hilightMode',
registry.String('q',"""mode used by the bot when hilight is triggered"""))
conf.registerChannelValue(ChanTracker, 'hilightDuration',
@ -276,11 +275,11 @@ registry.String('notice detected',"""comment added on mode changes database, emp
# channel ctcps
conf.registerChannelValue(ChanTracker, 'ctcpPermit',
registry.Integer(-1,"""Number of messages allowed, -1 to disable, advice 0"""))
registry.Integer(-1,"""Number of messages allowed, -1 to disable"""))
conf.registerChannelValue(ChanTracker, 'ctcpLife',
registry.PositiveInteger(3,"""Duration in seconds before messages are removed from count"""))
conf.registerChannelValue(ChanTracker, 'ctcpMode',
registry.String('b',"""mode used by the bot when cycle is triggered"""))
registry.String('b',"""mode used by the bot when ctcp detection is triggered"""))
conf.registerChannelValue(ChanTracker, 'ctcpDuration',
registry.PositiveInteger(1800,"""punishment duration in seconds"""))
conf.registerChannelValue(ChanTracker, 'ctcpComment',
@ -290,9 +289,9 @@ registry.String('ctcp detected',"""comment added on mode changes database, empty
conf.registerChannelValue(ChanTracker, 'cyclePermit',
registry.Integer(-1,"""Number of cycles allowed, -1 to disable, count part and quit"""))
conf.registerChannelValue(ChanTracker, 'cycleLife',
registry.PositiveInteger(180,"""Duration in seconds before cycles are removed from count, advice 180"""))
registry.PositiveInteger(180,"""Duration in seconds before cycles are removed from count"""))
conf.registerChannelValue(ChanTracker, 'cycleMode',
registry.String('b',"""mode used by the bot when ctcp is triggered"""))
registry.String('b',"""mode used by the bot when cycle detection is triggered"""))
conf.registerChannelValue(ChanTracker, 'cycleDuration',
registry.PositiveInteger(1800,"""punishment duration in seconds"""))
conf.registerChannelValue(ChanTracker, 'cycleComment',
@ -314,9 +313,9 @@ registry.String('-rq+z $~a',"""mode used by the bot when massJoinDuration is fin
# nick changes flood
conf.registerChannelValue(ChanTracker, 'nickPermit',
registry.Integer(-1,"""Number of nick changes allowed, -1 to disable, advice 2"""))
registry.Integer(-1,"""Number of nick changes allowed, -1 to disable"""))
conf.registerChannelValue(ChanTracker, 'nickLife',
registry.Integer(300,"""Duration in seconds before nick changes are removed from count, advice 300"""))
registry.Integer(300,"""Duration in seconds before nick changes are removed from count"""))
conf.registerChannelValue(ChanTracker, 'nickMode',
registry.String('q',"""mode used by the bot when nick is triggered"""))
conf.registerChannelValue(ChanTracker, 'nickDuration',
@ -326,9 +325,9 @@ registry.String('nick changes flood detected',"""comment added on mode changes d
# if you enable this, each time someone trigger other protection that will increase this queue
conf.registerChannelValue(ChanTracker, 'badPermit',
registry.Integer(-1,"""Number of bad action allowed, -1 to disable, advice 2, each time bot had to acts on a user, it increase this item"""))
registry.Integer(-1,"""Number of bad action allowed, -1 to disable, each time bot had to acts on a user, it increase this item"""))
conf.registerChannelValue(ChanTracker, 'badLife',
registry.Integer(600,"""Duration in seconds before actions are removed from count, advice 600"""))
registry.Integer(600,"""Duration in seconds before actions are removed from count"""))
conf.registerChannelValue(ChanTracker, 'badMode',
registry.String('b',"""mode used by the bot when bad is triggered"""))
conf.registerChannelValue(ChanTracker, 'badDuration',
@ -338,9 +337,9 @@ registry.String('bad detected',"""comment added on mode changes database, empty
# if you enable this, each time someone trigger bad in a channel that will increase this queue
conf.registerChannelValue(ChanTracker, 'attackPermit',
registry.Integer(-1,"""Number of bad action allowed, -1 to disable, advice 2, each time bot flags user as bad, it increase this item"""))
registry.Integer(-1,"""Number of bad action allowed, -1 to disable, each time bot flags user as bad, it increase this item"""))
conf.registerChannelValue(ChanTracker, 'attackLife',
registry.Integer(600,"""Duration in seconds before actions are removed from count, advice 600"""))
registry.Integer(600,"""Duration in seconds before actions are removed from count"""))
conf.registerChannelValue(ChanTracker, 'attackDuration',
registry.PositiveInteger(1800,"""punishment duration in seconds"""))
conf.registerChannelValue(ChanTracker, 'attackMode',

View File

@ -3224,7 +3224,8 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
def _isSomething (self,irc,channel,key,prop):
chan = self.getChan(irc,channel)
if prop == 'massJoin' or prop == 'cycle' and chan.netsplit:
if prop == 'massJoin' or prop == 'cycle':
if chan.netsplit:
return False
limit = self.registryValue('%sPermit' % prop,channel=channel)
if limit < 0:
@ -3308,35 +3309,39 @@ class ChanTracker(callbacks.Plugin,plugins.ChannelDBHandler):
if not channel in chan.repeatLogs or chan.repeatLogs[channel].timeout != life:
chan.repeatLogs[channel] = utils.structures.TimeoutQueue(life)
patchan = 'pattern%s' % channel
# specific case where bot will try to find the largest pattern to use
if self.registryValue('massRepeatPatternLength',channel=channel) > 0:
if not patchan in chan.repeatLogs or chan.repeatLogs[patchan].timeout != self.registryValue('massRepeatPatternLife',channel=channel):
chan.repeatLogs[patchan] = utils.structures.TimeoutQueue(self.registryValue('massRepeatPatternLife',channel=channel))
logs = chan.repeatLogs[patchan]
for msg in logs:
# if we find the string in the message, then
if message.find(msg) != -1:
# increment massrepeat trigger
self._isSomething(irc,channel,channel,'massRepeat')
chan.repeatLogs[channel].enqueue(message)
# self.log.debug('mass repeat "%s" is found in "%s"' % (msg,message))
#self._isSomething(irc,channel,channel,'massRepeat')
return True
logs = chan.repeatLogs[channel]
trigger = self.registryValue('massRepeatPercent',channel=channel)
result = False
flag = False
pattern = None
for msg in logs:
if self._strcompare(message,msg) >= trigger:
# self.log.debug('mass repeat "%s" matchs "%s"' % (message,msg))
if self.registryValue('massRepeatPatternLength',channel=channel) > 0:
if not patchan in chan.repeatLogs or chan.repeatLogs[patchan].timeout != self.registryValue('massRepeatPatternLife',channel=channel):
chan.repeatLogs[patchan] = utils.structures.TimeoutQueue(self.registryValue('massRepeatPatternLife',channel=channel))
pattern = self._largestpattern(message,msg)
if pattern and len(pattern) > self.registryValue('massRepeatPatternLength',channel=channel):
self.log.debug('mass repeat pattern added %s' % pattern)
chan.repeatLogs[patchan].enqueue(pattern)
pattern = pattern
else:
pattern = None
flag = True
break
if flag:
result = self._isSomething(irc,channel,channel,'massRepeat')
# self.log.debug('mass repeat flagged and %s : "%s" / %s' % (result,message,pattern))
if result and pattern:
if not patchan in chan.repeatLogs or chan.repeatLogs[patchan].timeout != self.registryValue('massRepeatPatternLife',channel=channel):
chan.repeatLogs[patchan] = utils.structures.TimeoutQueue(self.registryValue('massRepeatPatternLife',channel=channel))
# self.log.debug('mass repeat pattern added "%s"' % pattern)
chan.repeatLogs[patchan].enqueue(pattern)
chan.repeatLogs[channel].enqueue(message)
return result