3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-19 10:29:30 +01:00

Added captcha and !unbanme command to allow unbanning from join flood

This commit is contained in:
Pragmatic Software 2010-06-16 01:55:29 +00:00
parent 460516d58b
commit 16b9bba71c
2 changed files with 70 additions and 3 deletions

View File

@ -45,6 +45,8 @@ sub initialize {
$self->{message_history} = {}; $self->{message_history} = {};
$pbot->timer->register(sub { $self->prune_message_history }, 60 * 60 * 1); $pbot->timer->register(sub { $self->prune_message_history }, 60 * 60 * 1);
$pbot->commands->register(sub { return $self->unbanme(@_) }, "unbanme", 0);
} }
sub get_flood_account { sub get_flood_account {
@ -154,6 +156,7 @@ sub check_flood {
if($max_messages > 0 and $length >= $max_messages) { if($max_messages > 0 and $length >= $max_messages) {
$self->{pbot}->logger->log("More than $max_messages messages, comparing time differences ($max_time)\n") if $mode == $self->{FLOOD_JOIN}; $self->{pbot}->logger->log("More than $max_messages messages, comparing time differences ($max_time)\n") if $mode == $self->{FLOOD_JOIN};
my %msg = %{ @{ ${ $self->message_history }{$account}{$channel}{messages} }[$length - $max_messages] }; my %msg = %{ @{ ${ $self->message_history }{$account}{$channel}{messages} }[$length - $max_messages] };
my %last = %{ @{ ${ $self->message_history }{$account}{$channel}{messages} }[$length - 1] }; my %last = %{ @{ ${ $self->message_history }{$account}{$channel}{messages} }[$length - 1] };
@ -163,11 +166,20 @@ sub check_flood {
if($mode == $self->{FLOOD_JOIN}) { if($mode == $self->{FLOOD_JOIN}) {
if(${ $self->message_history }{$account}{$channel}{join_watch} >= $max_messages) { if(${ $self->message_history }{$account}{$channel}{join_watch} >= $max_messages) {
${ $self->message_history }{$account}{$channel}{offenses}++; ${ $self->message_history }{$account}{$channel}{offenses}++;
my $timeout = (2 ** (${ $self->message_history }{$account}{$channel}{offenses} < 6 ? ${ $self->message_history }{$account}{$channel}{offenses} : 6)); my $timeout = (2 ** (${ $self->message_history }{$account}{$channel}{offenses} < 6 ? ${ $self->message_history }{$account}{$channel}{offenses} : 6));
$self->{pbot}->chanops->quiet_user_timed("*!$user\@$host", $channel, $timeout * 60 * 60); $self->{pbot}->chanops->quiet_user_timed("*!$user\@$host", $channel, $timeout * 60 * 60);
$self->{pbot}->logger->log("$nick!$user\@$host banned for $timeout hours due to join flooding (offense #${ $self->message_history }{$account}{$channel}{offenses}).\n"); $self->{pbot}->logger->log("$nick!$user\@$host banned for $timeout hours due to join flooding (offense #${ $self->message_history }{$account}{$channel}{offenses}).\n");
$timeout = "several" if($timeout > 8); $timeout = "several" if($timeout > 8);
$self->{pbot}->conn->privmsg($nick, "You have been banned from $channel for $timeout hours due to join flooding.");
my $captcha = generate_random_string(7);
${ $self->message_history }{$account}{$channel}{captcha} = $captcha;
$self->{pbot}->conn->privmsg($nick, "You have been banned from $channel for $timeout hours due to join flooding. If your connection issues have been fixed, or this was an accident, you may request an unban by responding to this message with: unbanme $channel $captcha");
${ $self->message_history }{$account}{$channel}{join_watch} = $max_messages - 2; # give them a chance to rejoin ${ $self->message_history }{$account}{$channel}{join_watch} = $max_messages - 2; # give them a chance to rejoin
} }
} elsif($mode == $self->{FLOOD_CHAT}) { } elsif($mode == $self->{FLOOD_CHAT}) {
@ -231,4 +243,59 @@ sub prune_message_history {
} }
} }
sub unbanme {
my ($self, $from, $nick, $user, $host, $arguments) = @_;
my ($channel, $captcha) = split / /, $arguments;
if(not defined $channel or not defined $captcha) {
return "/msg $nick Usage: unbanme <channel> <captcha>";
}
my $mask = "*!$user\@$host";
if(not exists $self->{pbot}->{chanops}->{quieted_masks}->{$mask}) {
return "/msg $nick There is no temporary ban set for $mask in channel $channel.";
}
if(not $self->{pbot}->chanops->{quieted_masks}->{$mask}{channel} eq $channel) {
return "/msg $nick There is no temporary ban set for $mask in channel $channel.";
}
my $account = $self->get_flood_account($nick, $user, $host);
if(not defined $account) {
return "/msg $nick I do not remember you.";
}
if(not exists $self->{message_history}->{$account}{$channel}{captcha}) {
return "/msg $nick I do not remember banning you in $channel.";
}
if(not $self->{message_history}->{$account}{$channel}{captcha} eq $captcha) {
return "/msg $nick Incorrect captcha.";
}
# TODO: these delete statements need to be abstracted to methods on objects
$self->{pbot}->chanops->unquiet_user($mask, $channel);
delete $self->{pbot}->chanops->{quieted_masks}->{$mask};
delete $self->{message_history}->{$account}{$channel}{captcha};
return "/msg $nick You have been unbanned from $channel.";
}
# based on Guy Malachi's code
sub generate_random_string {
my $length_of_randomstring = shift;
my @chars=('a'..'z','A'..'Z','0'..'9','_');
my $random_string;
foreach (1..$length_of_randomstring) {
$random_string .= $chars[rand @chars];
}
return $random_string;
}
1; 1;

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 165, BUILD_REVISION => 167,
BUILD_DATE => "2010-06-14", BUILD_DATE => "2010-06-15",
}; };
1; 1;