From e65d84960ab1d73648d4cc5e3ed04b7739147af7 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 2 Jun 2018 00:06:21 -0700 Subject: [PATCH] antispam: make punishments method-specific --- example-conf.yml | 7 ++++++- plugins/antispam.py | 10 ++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/example-conf.yml b/example-conf.yml index ac9f547..9f8375e 100644 --- a/example-conf.yml +++ b/example-conf.yml @@ -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 diff --git a/plugins/antispam.py b/plugins/antispam.py index fe91136..e2a471e 100644 --- a/plugins/antispam.py +++ b/plugins/antispam.py @@ -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)