aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-10-12 14:14:45 +1300
committerDavid Phillips <david@sighup.nz>2017-10-12 14:14:45 +1300
commit8714b27669ec7032a31ef88a8c8c451bcee56552 (patch)
treebd774f683640e77a4595b4e06ccffa34e397523f
parent8bc6d6e2f50c2986d2e431af9a994af687f27a40 (diff)
downloadidalius-8714b27669ec7032a31ef88a8c8c451bcee56552.tar.xz
Add antiflood module, expose $irc to modules
-rwxr-xr-xidalius.pl2
-rw-r--r--plugin/antiflood.pm39
-rw-r--r--plugin/tittilate.pm2
-rw-r--r--plugin/url_title.pm2
4 files changed, 42 insertions, 3 deletions
diff --git a/idalius.pl b/idalius.pl
index 2215b4e..ff89939 100755
--- a/idalius.pl
+++ b/idalius.pl
@@ -127,7 +127,7 @@ sub irc_public {
for my $module (@plugin_list) {
my $stripped_what = strip_color(strip_formatting($what));
- my $output = $module->message(\&log_info, $irc->nick_name, $who, $where, $what, $stripped_what);
+ my $output = $module->message(\&log_info, $irc->nick_name, $who, $where, $what, $stripped_what, $irc);
$irc->yield(privmsg => $where => $output) if $output;
}
diff --git a/plugin/antiflood.pm b/plugin/antiflood.pm
new file mode 100644
index 0000000..d9326ba
--- /dev/null
+++ b/plugin/antiflood.pm
@@ -0,0 +1,39 @@
+#!/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 $cref = $_[1];
+ %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];
+
+ my $now = time();
+ push @{$lastmsg{$nick}}, $now;
+
+ # FIXME limit buffer size to 5
+ if (@{$lastmsg{$nick}} >= $message_count) {
+ my $first = @{$lastmsg{$nick}}[0];
+ if ($now - $first <= $message_period) {
+ $irc->yield(kick => $channel => $nick => "Flood");
+ }
+ }
+ return;
+}
+1;
diff --git a/plugin/tittilate.pm b/plugin/tittilate.pm
index 51253ec..7a1ecd5 100644
--- a/plugin/tittilate.pm
+++ b/plugin/tittilate.pm
@@ -15,7 +15,7 @@ sub configure {
}
sub message {
- my ($self, $logger, $me, $who, $where, $raw_what, $what) = @_;
+ my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
my $gathered = "";
my @expressions = (keys %{$config{triggers}});
my $expression = join '|', @expressions;
diff --git a/plugin/url_title.pm b/plugin/url_title.pm
index 1c376df..9deaae2 100644
--- a/plugin/url_title.pm
+++ b/plugin/url_title.pm
@@ -18,7 +18,7 @@ sub configure {
sub message
{
- my ($self, $logger, $me, $who, $where, $raw_what, $what) = @_;
+ my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
my $url;
if ($what =~ /(https?:\/\/[^ ]+)/i) {