diff --git a/PBot/AntiFlood.pm b/PBot/AntiFlood.pm index 036cde6c..22b4ae7a 100644 --- a/PBot/AntiFlood.pm +++ b/PBot/AntiFlood.pm @@ -93,20 +93,33 @@ sub check_flood { if($last{timestamp} - $msg{timestamp} <= 10 && not $self->{pbot}->admins->loggedin($channel, "$nick!$user\@$host")) { ${ $self->message_history }{$nick}{$channel}{offenses}++; - my $length = ${ $self->message_history }{$nick}{$channel}{offenses} * ${ $self->message_history }{$nick}{$channel}{offenses} * 30; + my $length = ${ $self->message_history }{$nick}{$channel}{offenses} ** ${ $self->message_history }{$nick}{$channel}{offenses} * ${ $self->message_history }{$nick}{$channel}{offenses} * 30; if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise) - return if exists $self->{pbot}->chanops->{quieted_nicks}->{$nick}; + return if exists $self->{pbot}->chanops->{quieted_masks}->{"*!*\@$host"}; if($mode == $self->{FLOOD_CHAT}) { - $self->{pbot}->chanops->quiet_nick_timed($nick, $channel, $length); - $self->{pbot}->conn->privmsg($nick, "You have been quieted due to flooding. Please use a web paste service such as http://codepad.org for lengthy pastes. You will be allowed to speak again in $length seconds."); + $self->{pbot}->chanops->quiet_user_timed("*!*\@$host", $channel, $length); + $self->{pbot}->logger->log("$nick $channel flood offense ${ $self->message_history }{$nick}{$channel}{offenses} earned $length second quiet\n"); + + if($length < 1000) { + $length = "$length seconds"; + } else { + $length = "a little while"; + } + + $self->{pbot}->conn->privmsg($nick, "You have been quieted due to flooding. Please use a web paste service such as http://codepad.org for lengthy pastes. You will be allowed to speak again in $length."); } } else { # private message flood return if exists $self->{pbot}->ignorelist->{ignore_list}->{"$nick!$user\@$host"}{$channel}; $self->{pbot}->logger->log("$nick msg flood offense ${ $self->message_history }{$nick}{$channel}{offenses} earned $length second ignore\n"); - $self->{pbot}->conn->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length seconds."); $self->{pbot}->{ignorelistcmds}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length"); + if($length < 1000) { + $length = "$length seconds"; + } else { + $length = "a little while"; + } + $self->{pbot}->conn->privmsg($nick, "You have used too many commands in too short a time period, you have been ignored for $length."); } } } @@ -135,8 +148,8 @@ sub prune_message_history { my $length = $#{ $self->{message_history}->{$nick}{$channel}{messages} } + 1; my %last = %{ @{ $self->{message_history}->{$nick}{$channel}{messages} }[$length - 1] }; - if(gettimeofday - $last{timestamp} >= 60 * 60 * 24) { - $self->{pbot}->logger->log("$nick in $channel hasn't spoken in 24 hours, removing message history.\n"); + if(gettimeofday - $last{timestamp} >= 60 * 60 * 24 * 3) { + $self->{pbot}->logger->log("$nick in $channel hasn't spoken in three days, removing message history.\n"); delete $self->{message_history}->{$nick}{$channel}; } } diff --git a/PBot/ChanOpCommands.pm b/PBot/ChanOpCommands.pm index 0e8e896d..9cb5e43f 100644 --- a/PBot/ChanOpCommands.pm +++ b/PBot/ChanOpCommands.pm @@ -57,7 +57,7 @@ sub quiet { } if(not defined $target) { - return "/msg $nick Usage: quiet nick [timeout seconds (default: 3600 or 1 hour)]"; + return "/msg $nick Usage: quiet [timeout seconds (default: 3600 or 1 hour)]"; } if(not defined $length) { @@ -66,8 +66,7 @@ sub quiet { return "" if $target =~ /\Q$self->{pbot}->botnick\E/i; - $self->{pbot}->chanops->quiet_nick_timed($target, $from, $length); - $self->{pbot}->conn->privmsg($target, "$nick has quieted you for $length seconds."); + $self->{pbot}->chanops->quiet_user_timed($target, $from, $length); } sub unquiet { @@ -82,15 +81,15 @@ sub unquiet { my ($target, $channel) = split / /, $arguments; if(not defined $target) { - return "/msg $nick Usage: unquiet [channel]"; + return "/msg $nick Usage: unquiet [channel]"; } $channel = $from if not defined $channel; return "/msg $nick Unquiet must be used against a channel. Either use in channel, or specify !unquiet $target " if $channel !~ /^#/; - $self->{pbot}->chanops->unquiet_nick($arguments, $from); - delete ${ $self->{pbot}->chanops->{quieted_nicks} }{$arguments}; + $self->{pbot}->chanops->unquiet_user($arguments, $from); + delete ${ $self->{pbot}->chanops->{quieted_masks} }{$arguments}; $self->{pbot}->conn->privmsg($arguments, "$nick has allowed you to speak again.") unless $arguments =~ /\Q$self->{pbot}->botnick\E/i; return "Done."; } diff --git a/PBot/ChanOps.pm b/PBot/ChanOps.pm index bdaffb90..8156f986 100644 --- a/PBot/ChanOps.pm +++ b/PBot/ChanOps.pm @@ -34,7 +34,7 @@ sub initialize { } $self->{pbot} = $pbot; - $self->{quieted_nicks} = {}; + $self->{quieted_masks} = {}; $self->{unban_timeouts} = {}; $self->{op_commands} = []; $self->{is_opped} = {}; @@ -85,42 +85,42 @@ sub perform_op_commands { $self->{pbot}->logger->log("Done.\n"); } -sub quiet_nick { +sub quiet_user { my $self = shift; - my ($nick, $channel) = @_; - unshift @{ $self->{op_commands} }, "mode $channel +q $nick!*@*"; + my ($mask, $channel) = @_; + unshift @{ $self->{op_commands} }, "mode $channel +b $mask"; $self->gain_ops($channel); } -sub unquiet_nick { +sub unquiet_user { my $self = shift; - my ($nick, $channel) = @_; - unshift @{ $self->{op_commands} }, "mode $channel -q $nick!*@*"; + my ($mask, $channel) = @_; + unshift @{ $self->{op_commands} }, "mode $channel -b $mask"; $self->gain_ops($channel); } -sub quiet_nick_timed { +sub quiet_user_timed { my $self = shift; - my ($nick, $channel, $length) = @_; + my ($mask, $channel, $length) = @_; - $self->quiet_nick($nick, $channel); - ${ $self->{quieted_nicks} }{$nick}{time} = gettimeofday + $length; - ${ $self->{quieted_nicks} }{$nick}{channel} = $channel; + $self->quiet_user($mask, $channel); + ${ $self->{quieted_masks} }{$mask}{time} = gettimeofday + $length; + ${ $self->{quieted_masks} }{$mask}{channel} = $channel; } sub check_quieted_timeouts { my $self = shift; my $now = gettimeofday(); - foreach my $nick (keys %{ $self->{quieted_nicks} }) { - if($self->{quieted_nicks}->{$nick}{time} < $now) { - $self->{pbot}->logger->log("Unquieting $nick\n"); - $self->unquiet_nick($nick, $self->{quieted_nicks}->{$nick}{channel}); - delete $self->{quieted_nicks}->{$nick}; - $self->{pbot}->conn->privmsg($nick, "You may speak again."); + foreach my $mask (keys %{ $self->{quieted_masks} }) { + if($self->{quieted_masks}->{$mask}{time} < $now) { + $self->{pbot}->logger->log("Unquieting $mask\n"); + $self->unquiet_mask($mask, $self->{quieted_masks}->{$mask}{channel}); + delete $self->{quieted_masks}->{$mask}; + $self->{pbot}->conn->privmsg($mask, "You may speak again."); } else { - #my $timediff = $quieted_nicks{$nick}{time} - $now; - #$logger->log "quiet: $nick has $timediff seconds remaining\n" + #my $timediff = $quieted_masks{$mask}{time} - $now; + #$logger->log "quiet: $mask has $timediff seconds remaining\n" } } }