3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 03:33:10 +01:00

antispam: make punishments method-specific

This commit is contained in:
James Lu 2018-06-02 00:06:21 -07:00
parent 8cc4527ff7
commit e65d84960a
2 changed files with 12 additions and 5 deletions

View File

@ -829,10 +829,15 @@ stats:
# false if not set.
#enabled: true
# Sets the punishment that Antispam should use to punish mass highlighters.
# Valid values include "kill", "kick", "ban", "quiet", and combinations of these strung
# together with "+" (e.g. "kick+ban"). Defaults to "kick+ban" if not set.
#punishment: kick+ban
# Sets the kick / kill message used when mass highlight prevention is triggered.
#reason: "Mass highlight spam is prohibited"
# Sets the minimum message length and amount of nicks needed in a message for
# masshighlight prevention to trigger.
# mass highlight prevention to trigger.
#min_length: 50
#min_nicks: 5

View File

@ -12,7 +12,7 @@ def die(irc=None):
PUNISH_OPTIONS = ['kill', 'ban', 'quiet', 'kick']
EXEMPT_OPTIONS = ['voice', 'halfop', 'op']
DEFAULT_EXEMPT_OPTION = 'halfop'
def _punish(irc, target, channel, reason):
def _punish(irc, target, channel, punishment, reason):
"""Punishes the target user. This function returns True if the user was successfully punished."""
if irc.is_oper(target, allowAuthed=False):
log.debug("(%s) antispam: refusing to punish oper %s/%s", irc.name, target, irc.get_friendly_name(target))
@ -42,8 +42,6 @@ def _punish(irc, target, channel, reason):
if irc.pseudoclient and not irc.has_cap('can-spawn-clients'):
my_uid = irc.pseudoclient.uid
punishment = irc.get_service_option('antispam', 'punishment',
'kick+ban').lower()
bans = set()
log.debug('(%s) antispam: got %r as punishment for %s/%s', irc.name, punishment,
target, irc.get_friendly_name(target))
@ -95,6 +93,7 @@ MASSHIGHLIGHT_DEFAULTS = {
'min_length': 50,
'min_nicks': 5,
'reason': "Mass highlight spam is prohibited",
'punishment': 'kick+ban',
'enabled': False
}
def handle_masshighlight(irc, source, command, args):
@ -147,10 +146,13 @@ def handle_masshighlight(irc, source, command, args):
if word in userlist:
nicks_caught.add(word)
if len(nicks_caught) >= min_nicks:
# Get the punishment and reason.
punishment = mhl_settings.get('punishment', MASSHIGHLIGHT_DEFAULTS['punishment']).lower()
reason = mhl_settings.get('reason', MASSHIGHLIGHT_DEFAULTS['reason'])
log.debug('(%s) antispam: calling _punish on %s/%s', irc.name,
source, irc.get_friendly_name(source))
punished = _punish(irc, source, channel, reason)
punished = _punish(irc, source, channel, punishment, reason)
break
log.debug('(%s) antispam: got %s/%s nicks on message to %r', irc.name, len(nicks_caught), min_nicks, channel)