From 81e6f71199f062a54e6f663f48921c8d763ab4e2 Mon Sep 17 00:00:00 2001 From: Janik Kleinhoff Date: Sun, 14 Feb 2016 02:11:51 +0000 Subject: splitflood: allow whitelisting certain regex per channel Accessible via editing the config only; this is a feature that is probably only useful to a handful of channels. --- lib/ASM/Classes.pm | 24 ++++++++++++++++++++++++ lib/ASM/Util.pm | 9 +++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/ASM/Classes.pm b/lib/ASM/Classes.pm index 8a0b36a..bee81e1 100644 --- a/lib/ASM/Classes.pm +++ b/lib/ASM/Classes.pm @@ -300,8 +300,14 @@ sub nickspam { my %cf=(); my %bs=(); my $cfc = 0; +my %fpo_seen; sub process_cf { + for my $fpoid (values %fpo_seen) { + for my $fptext (keys %$fpoid) { + delete $fpoid->{$fptext} if $fpoid->{$fptext} <= time; + } + } foreach my $nid ( keys %cf ) { foreach my $xchan ( keys %{$cf{$nid}} ) { next if $xchan eq 'timeout'; @@ -321,6 +327,22 @@ sub process_cf } } +# this is a mess, sorry about that +sub fpo { + my ($chan, $nick, $text, $how_long) = @_; + + return undef unless ASM::Util->isFloodedPhraseOK($chan, $text); + + my $okay = 0; + + if ( ( $fpo_seen{$chan}{ $::sn{$nick}{host} }{$text} // 0 ) <= time) { + $okay = 1; + } + + $fpo_seen{$chan}{ $::sn{$nick}{host} }{$text} = time + $how_long; + return $okay; +} + sub splitflood { my ($chk, $id, $event, $chan) = @_; my $text; @@ -337,6 +359,7 @@ sub splitflood { my $msgtime = $::sc{$chan}{users}{$nick}{msgtime} // 0; $msgtime ||= 1 if !$::sc{$chan}{users}{$nick}{jointime}; return if $text =~ /^[^\w\s]+\w+\s*$/ && $msgtime && ($msgtime + $cf{$id}{timeout}) < time; + return if fpo($chan, $nick, $text, 2 * int($cut[1])); # return unless length($text) >= 10; if (defined($bs{$id}{$text}) && (time <= $bs{$id}{$text} + 600)) { return 1; @@ -367,6 +390,7 @@ sub advsplitflood { $text=$event->{args}->[0]; } return unless defined($text); + return if fpo($chan, lc $event->{nick}, $text, 3 * int($cut[1])); $text=~s/^\d*(.*)\d*$/$1/; return unless length($text) >= 10; if (defined($bs{$id}{$text}) && (time <= $bs{$id}{$text} + 600)) { diff --git a/lib/ASM/Util.pm b/lib/ASM/Util.pm index 6372037..4b0137d 100644 --- a/lib/ASM/Util.pm +++ b/lib/ASM/Util.pm @@ -131,6 +131,15 @@ sub mayAlert { return !( ($::channels->{channel}{lc $chan}{monitor} // 'yes') eq 'no' || $module->isSuppressed($chan) ); } +sub isFloodedPhraseOK { + my ($module, $chan, $text) = @_; + + return undef unless exists $::channels->{channel}{$chan}{floodedphraseok}; + my $exempt_regex = $::channels->{channel}{$chan}{floodedphraseok}; + + return $text =~ $exempt_regex; +} + #this item is a stub, dur sub hostip { return gethostbyname($_[0]); -- cgit v1.2.3