3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-01-30 14:04:16 +01:00

unban_timeouts is now a HashObject -- consequently, unban timeouts now save to and load from data file

This commit is contained in:
Pragmatic Software 2010-06-18 10:46:23 +00:00
parent e32850aae2
commit fe96faded8
8 changed files with 48 additions and 16 deletions

View File

@ -190,7 +190,7 @@ sub check_flood {
${ $self->message_history }{$account}{$channel}{offenses}++; ${ $self->message_history }{$account}{$channel}{offenses}++;
my $length = ${ $self->message_history }{$account}{$channel}{offenses} ** ${ $self->message_history }{$account}{$channel}{offenses} * ${ $self->message_history }{$account}{$channel}{offenses} * 30; my $length = ${ $self->message_history }{$account}{$channel}{offenses} ** ${ $self->message_history }{$account}{$channel}{offenses} * ${ $self->message_history }{$account}{$channel}{offenses} * 30;
if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise) if($channel =~ /^#/) { #channel flood (opposed to private message or otherwise)
return if exists $self->{pbot}->chanops->{unban_timeout}->{"*!*\@$host"}; return if exists $self->{pbot}->chanops->{unban_timeout}->hash->{"*!*\@$host"};
if($mode == $self->{FLOOD_CHAT}) { if($mode == $self->{FLOOD_CHAT}) {
$self->{pbot}->chanops->ban_user_timed("*!$user\@$host", $channel, $length); $self->{pbot}->chanops->ban_user_timed("*!$user\@$host", $channel, $length);
@ -260,11 +260,11 @@ sub unbanme {
my $mask = "*!$user\@$banmask\$##fix_your_connection"; my $mask = "*!$user\@$banmask\$##fix_your_connection";
if(not exists $self->{pbot}->{chanops}->{unban_timeout}->{$mask}) { if(not exists $self->{pbot}->{chanops}->{unban_timeout}->hash->{$mask}) {
return "/msg $nick There is no temporary ban set for $mask in channel $channel."; return "/msg $nick There is no temporary ban set for $mask in channel $channel.";
} }
if(not $self->{pbot}->chanops->{unban_timeout}->{$mask}{channel} eq $channel) { if(not $self->{pbot}->chanops->{unban_timeout}->hash->{$mask}{channel} eq $channel) {
return "/msg $nick There is no temporary ban set for $mask in channel $channel."; return "/msg $nick There is no temporary ban set for $mask in channel $channel.";
} }
@ -284,7 +284,8 @@ sub unbanme {
# TODO: these delete statements need to be abstracted to methods on objects # TODO: these delete statements need to be abstracted to methods on objects
$self->{pbot}->chanops->unban_user($mask, $channel); $self->{pbot}->chanops->unban_user($mask, $channel);
delete $self->{pbot}->chanops->{unban_timeout}->{$mask}; delete $self->{pbot}->chanops->{unban_timeout}->hash->{$mask};
$self->{pbot}->chanops->{unban_timeout}->save_hash();
delete $self->{message_history}->{$account}{$channel}{captcha}; delete $self->{message_history}->{$account}{$channel}{captcha};
return "/msg $nick You have been unbanned from $channel."; return "/msg $nick You have been unbanned from $channel.";

View File

@ -87,7 +87,8 @@ sub unban_user {
return "/msg $nick Usage for /msg: !unban $target <channel>" if $channel !~ /^#/; return "/msg $nick Usage for /msg: !unban $target <channel>" if $channel !~ /^#/;
$self->{pbot}->chanops->unban_user($arguments, $from); $self->{pbot}->chanops->unban_user($arguments, $from);
delete ${ $self->{pbot}->chanops->{unban_timeout} }{$arguments}; delete $self->{pbot}->chanops->{unban_timeout}->hash->{$arguments};
$self->{pbot}->chanops->{unban_timeout}->save_hash();
return "/msg $nick $arguments has been unbanned."; return "/msg $nick $arguments has been unbanned.";
} }

View File

@ -12,6 +12,7 @@ use vars qw($VERSION);
$VERSION = $PBot::PBot::VERSION; $VERSION = $PBot::PBot::VERSION;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use PBot::HashObject;
sub new { sub new {
if(ref($_[1]) eq 'HASH') { if(ref($_[1]) eq 'HASH') {
@ -34,7 +35,7 @@ sub initialize {
} }
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
$self->{unban_timeout} = {}; $self->{unban_timeout} = PBot::HashObject->new(pbot => $pbot, name => 'Unban Timeouts', index_key => 'banmask', filename => "$pbot->{data_dir}/unban_timeouts");
$self->{op_commands} = []; $self->{op_commands} = [];
$self->{is_opped} = {}; $self->{is_opped} = {};
@ -99,19 +100,24 @@ sub ban_user_timed {
my ($mask, $channel, $length) = @_; my ($mask, $channel, $length) = @_;
$self->ban_user($mask, $channel); $self->ban_user($mask, $channel);
${ $self->{unban_timeout} }{$mask}{timeout} = gettimeofday + $length; $self->{unban_timeout}->hash->{$mask}{timeout} = gettimeofday + $length;
${ $self->{unban_timeout} }{$mask}{channel} = $channel; $self->{unban_timeout}->hash->{$mask}{channel} = $channel;
$self->{unban_timeout}->save_hash();
} }
sub check_unban_timeouts { sub check_unban_timeouts {
my $self = shift; my $self = shift;
return if not $self->{pbot}->{joined_channels};
my $now = gettimeofday(); my $now = gettimeofday();
foreach my $mask (keys %{ $self->{unban_timeout} }) { foreach my $mask (keys %{ $self->{unban_timeout}->hash }) {
if($self->{unban_timeout}->{$mask}{timeout} < $now) { if($self->{unban_timeout}->hash->{$mask}{timeout} < $now) {
$self->{pbot}->logger->log("Unbanning $mask\n"); $self->{pbot}->logger->log("Unbanning $mask\n");
$self->unban_user($mask, $self->{unban_timeout}->{$mask}{channel}); $self->unban_user($mask, $self->{unban_timeout}->hash->{$mask}{channel});
delete $self->{unban_timeout}->{$mask}; delete $self->{unban_timeout}->hash->{$mask};
$self->{unban_timeout}->save_hash();
} else { } else {
#my $timediff = $unban_timeout{$mask}{timeout} - $now; #my $timediff = $unban_timeout{$mask}{timeout} - $now;
#$logger->log "ban: $mask has $timediff seconds remaining\n" #$logger->log "ban: $mask has $timediff seconds remaining\n"

View File

@ -101,7 +101,11 @@ sub load_hash {
$self->{pbot}->logger->log("Loading $self->{name} objects from $filename ...\n"); $self->{pbot}->logger->log("Loading $self->{name} objects from $filename ...\n");
open(FILE, "< $filename") or Carp::croak "Couldn't open $filename: $!\n"; if(not open(FILE, "< $filename")) {
Carp::carp "Couldn't open $filename: $!\n";
Carp::carp "Skipping loading from file.\n";
return;
}
my $i = 0; my $i = 0;
my $hash; my $hash;

View File

@ -99,6 +99,7 @@ sub on_notice {
$conn->join($chan); $conn->join($chan);
} }
} }
$self->{pbot}->{joined_channels} = 1;
} }
} }
@ -136,8 +137,9 @@ sub on_mode {
} else { # bot not targeted } else { # bot not targeted
if($mode eq "+b") { if($mode eq "+b") {
if($nick eq "ChanServ") { if($nick eq "ChanServ") {
$self->{pbot}->chanops->{unban_timeout}->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours $self->{pbot}->chanops->{unban_timeout}->hash->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours
$self->{pbot}->chanops->{unban_timeout}->{$target}{channel} = $channel; $self->{pbot}->chanops->{unban_timeout}->hash->{$target}{channel} = $channel;
$self->{pbot}->chanops->{unban_timeout}->save_hash();
} }
} elsif($mode eq "+e" && $channel eq $self->{pbot}->botnick) { } elsif($mode eq "+e" && $channel eq $self->{pbot}->botnick) {
foreach my $chan (keys %{ $self->{pbot}->channels->channels->hash }) { foreach my $chan (keys %{ $self->{pbot}->channels->channels->hash }) {
@ -146,6 +148,7 @@ sub on_mode {
$self->{pbot}->conn->join($chan); $self->{pbot}->conn->join($chan);
} }
} }
$self->{pbot}->{joined_channels} = 1;
} }
} }
} }

View File

@ -64,6 +64,15 @@ sub initialize {
my ($self, %conf) = @_; my ($self, %conf) = @_;
my $log_file = delete $conf{log_file}; my $log_file = delete $conf{log_file};
my $conf_dir = delete $conf{conf_dir};
$conf_dir = "$ENV{HOME}/pbot/data" unless defined $conf_dir;
$self->{conf_dir} = $conf_dir;
my $data_dir = delete $conf{data_dir};
$data_dir = "$ENV{HOME}/pbot/data" unless defined $data_dir;
$self->{data_dir} = $data_dir;
my $channels_file = delete $conf{channels_file}; my $channels_file = delete $conf{channels_file};
my $admins_file = delete $conf{admins_file}; my $admins_file = delete $conf{admins_file};
@ -155,6 +164,8 @@ sub initialize {
$self->{chanops} = PBot::ChanOps->new(pbot => $self); $self->{chanops} = PBot::ChanOps->new(pbot => $self);
$self->{chanopcmds} = PBot::ChanOpCommands->new(pbot => $self); $self->{chanopcmds} = PBot::ChanOpCommands->new(pbot => $self);
$self->{chanops}->{unban_timeout}->load_hash();
$self->{quotegrabs} = PBot::Quotegrabs->new( $self->{quotegrabs} = PBot::Quotegrabs->new(
pbot => $self, pbot => $self,
filename => $quotegrabs_file, filename => $quotegrabs_file,

View File

@ -13,7 +13,7 @@ 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 => 175, BUILD_REVISION => 176,
BUILD_DATE => "2010-06-18", BUILD_DATE => "2010-06-18",
}; };

View File

@ -59,6 +59,12 @@ my %config = (
# You shouldn't need to change anything below this line. # You shouldn't need to change anything below this line.
# ----------------------------------------------------- # -----------------------------------------------------
# Path to data directory
data_dir => "$bothome/data",
# Path to config directory
conf_dir => "$bothome/config",
# Path to directory containing external script-like modules # Path to directory containing external script-like modules
module_dir => "$bothome/modules", module_dir => "$bothome/modules",