From 5e157d2344cfcedfdb1fb96559c8de18bb5832e0 Mon Sep 17 00:00:00 2001 From: Daniel B Date: Wed, 20 Apr 2016 19:52:47 +0200 Subject: [PATCH] Possibility to set the number of "strikes" for the karma plugin (#254) The default behaviour (connection needs to have at least 3 or -3 to be considered nice or naughty) is not always what we want, depending on the number of plugins which adjust the karma. Lets make it configurable --- plugins/karma | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/karma b/plugins/karma index 04b8141..669aba0 100644 --- a/plugins/karma +++ b/plugins/karma @@ -50,6 +50,16 @@ With the default negative limit of one, there's a very small chance you could penalize a "mostly good" sender. Raising it to 2 reduces that possibility to improbable. +=head2 strikes + +How many strikes are needed to consider the connection nice or naughty. +Various plugins can adjust the karma (see USING KARMA IN OTHER PLUGINS). +For example, with the default value of 3, if the karma of this message is 3 +or above, the connection is considered to be a nice one. If it's -3 or less, +it's considered a naughty one. Between -2 and +2 it's neutral + +Default: 3 + =head2 penalty_days The number of days a naughty sender is refused connections. Use a decimal @@ -238,6 +248,7 @@ sub register { $self->log(LOGERROR, "Bad arguments") if @_ % 2; $self->{_args} = {@_}; $self->{_args}{negative} ||= 1; + $self->{_args}{strikes} ||= 3; $self->{_args}{penalty_days} ||= 1; $self->{_args}{reject_type} ||= 'disconnect'; @@ -428,7 +439,7 @@ sub disconnect_handler { my $history = ($nice || 0) - $naughty; my $log_mess = ''; - if ($karma < -2) { # they achieved at least 2 strikes + if ($karma <= $self->{_args}{strikes}) { # Enough negative strikes ? $history--; my $negative_limit = 0 - $self->{_args}{negative}; if ($history <= $negative_limit) { @@ -445,7 +456,7 @@ sub disconnect_handler { $log_mess = "negative"; } } - elsif ($karma > 2) { + elsif ($karma >= $self->{_args}{strikes}) { $nice++; $log_mess = "positive"; }