blob: eafa50c7663571565022aef8d956a0160fe8915c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
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 on_message {
my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
my $channel = $where->[0];
my $nick = (split /!/, $who)[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;
}
sub on_action {
on_message(@_);
}
1;
|