From cd1fc57841deab0e9b8bcfad49d527c6b263534c Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 10 Apr 2018 15:20:24 +1200 Subject: Correct capitalisation on module names --- Plugin/Antiflood.pm | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Plugin/Antiflood.pm (limited to 'Plugin/Antiflood.pm') diff --git a/Plugin/Antiflood.pm b/Plugin/Antiflood.pm new file mode 100644 index 0000000..4db7ace --- /dev/null +++ b/Plugin/Antiflood.pm @@ -0,0 +1,42 @@ +#!/usr/bin/env perl + +package Plugin::Antiflood; + +use strict; +use warnings; + +my $message_count = 5; +my $message_period = 11; + + +my %config; +my %lastmsg = (); + +sub configure { + my $self = $_[0]; + my $cmdref = $_[1]; + my $cref = $_[2]; + %config = %$cref; + return $self; +} + +sub message { + my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_; + my $channel = $where->[0]; + my $nick = (split /!/, $who)[0]; + + return if ($config{antiflood_on} == 0); + + my $now = time(); + push @{$lastmsg{$nick}}, $now; + + if (@{$lastmsg{$nick}} >= $message_count) { + @{$lastmsg{$nick}} = splice @{$lastmsg{$nick}}, 1, $message_count - 1; + my $first = @{$lastmsg{$nick}}[0]; + if ($now - $first <= $message_period) { + $irc->yield(kick => $channel => $nick => "Flood"); + } + } + return; +} +1; -- cgit v1.1