aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-01-03 20:33:11 +1300
committerDavid Phillips <david@sighup.nz>2018-01-03 20:33:11 +1300
commitafe5fc41fa45b4fbc2b12103f7e8bbb4e1dc706a (patch)
tree005c9dde3ca5a83badea4e3aa0a2d03bea140ebf
parent1e004d22dbccdfff4d8cce8a4c12bd0fe6a49a81 (diff)
downloadidalius-afe5fc41fa45b4fbc2b12103f7e8bbb4e1dc706a.tar.xz
Ignore users who summon responses from bot too quickly
-rwxr-xr-xidalius.pl22
1 files changed, 22 insertions, 0 deletions
diff --git a/idalius.pl b/idalius.pl
index 8e69f51..85fad47 100755
--- a/idalius.pl
+++ b/idalius.pl
@@ -13,6 +13,7 @@ use Module::Pluggable search_path => "plugin", instantiate => 'configure';
my $config_file = "bot.conf";
my %config = config_file::parse_config($config_file);
+my %laststrike = ();
$| = 1;
@@ -75,6 +76,26 @@ sub log_info {
print "$stamp | @_\n";
}
+# Add a strike against a nick for module flood protection
+# This differs from antiflood.pm in that it is used only for when users have
+# triggered a response from the bot.
+sub strike_add {
+ my $strike_count = 15;
+ my $strike_period = 30;
+
+ my ($nick) = @_;
+ my $now = time();
+ push @{$laststrike{$nick}}, $now;
+ if (@{$laststrike{$nick}} >= $strike_count) {
+ @{$laststrike{$nick}} = splice @{$laststrike{$nick}}, 1, $strike_count - 1;
+ my $first = @{$laststrike{$nick}}[0];
+ if ($now - $first <= $strike_period) {
+ log_info "Ignoring $nick because of command flood\n";
+ push @{$config{ignore}}, $nick;
+ }
+ }
+}
+
sub _start {
my $heap = $_[HEAP];
my $irc = $heap->{irc};
@@ -128,6 +149,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, $irc);
+ strike_add $nick if $output;
$irc->yield(privmsg => $where => $output) if $output;
}