From bd5a3db4a5d2b4ef6399593176e2e40b8a534f51 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 23 Feb 2019 06:33:22 +1300 Subject: Hmm: Add line-count cool-off --- Plugin/Hmm.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Plugin/Hmm.pm b/Plugin/Hmm.pm index e3909a0..7f5814a 100644 --- a/Plugin/Hmm.pm +++ b/Plugin/Hmm.pm @@ -6,6 +6,7 @@ use warnings; my $root_config; my $config; my %current_alarm; +my %lines_since; sub configure { my $self = shift; @@ -16,6 +17,7 @@ sub configure { IdaliusConfig::assert_scalar($config, $self, "min_delay_sec"); IdaliusConfig::assert_scalar($config, $self, "max_delay_sec"); + IdaliusConfig::assert_scalar($config, $self, "lines_break"); return $self; } @@ -34,6 +36,9 @@ sub on_message { return if ref($where) ne "ARRAY"; $where = $where->[0]; + # Require some minimum number of lines in a channel before hmming again + return unless $lines_since{$where}++ >= $config->{lines_break}; + if (defined $current_alarm{$where}) { $irc->delay_remove($current_alarm{$where}); } @@ -43,6 +48,8 @@ sub on_message { $current_alarm{$where} = $irc->delay([privmsg => $where => $response], $config->{min_delay_sec} + rand($config->{max_delay_sec} - $config->{min_delay_sec})); + $lines_since{$where} = 0; + return; } -- cgit v1.1