3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 13:59:47 +01:00

Replaced mode +q with mode +b for quieting; replaced nick!*@* with *!*@host in anti-flood; quiet commands take mask instead of nick

This commit is contained in:
Pragmatic Software 2010-05-30 02:02:29 +00:00
parent 0b3aa9015b
commit 7399f4ff91
3 changed files with 45 additions and 33 deletions

View File

@ -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};
}
}

View File

@ -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 <mask> [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 <nick> [channel]";
return "/msg $nick Usage: unquiet <mask> [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 <channel>" 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.";
}

View File

@ -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"
}
}
}