3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 01:48:38 +02:00

Add registry get_array_value() subroutine

This commit is contained in:
Pragmatic Software 2014-05-19 09:55:47 +00:00
parent 349afd4ae0
commit 710bbb76cc
3 changed files with 22 additions and 13 deletions

View File

@ -276,8 +276,7 @@ sub check_flood {
$channel_data->{enter_abuse} = $enter_abuse_threshold / 2 - 1;
if(++$channel_data->{enter_abuses} >= $enter_abuse_max_offenses) {
my $offenses = $channel_data->{enter_abuses} - $enter_abuse_max_offenses + 1;
my @punishment = $self->{pbot}->{registry}->get_value('antiflood', 'enter_abuse_punishment');
my $ban_length = $punishment[$offenses - 1 > $#punishment ? $#punishment : $offenses - 1];
my $ban_length = $self->{pbot}->{registry}->get_array_value('antiflood', 'enter_abuse_punishment', $offenses - 1);
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $channel, $ban_length);
$ban_length = duration($ban_length);
$self->{pbot}->{logger}->log("$nick $channel enter abuse offense " . $channel_data->{enter_abuses} . " earned $ban_length ban\n");
@ -343,8 +342,7 @@ sub check_flood {
$channel_data->{offenses}++;
$channel_data->{last_offense} = gettimeofday;
my @punishment = $self->{pbot}->{registry}->get_value('antiflood', 'join_flood_punishment');
my $timeout = $punishment[$channel_data->{offenses} - 1 > $#punishment ? $#punishment : $channel_data->{offenses} - 1];
my $timeout = $self->{pbot}->{registry}->get_array_value('antiflood', 'join_flood_punishment', $channel_data->{offenses} - 1);
my $duration = duration($timeout);
my $banmask = address_to_mask($host);
@ -364,8 +362,7 @@ sub check_flood {
$channel_data->{last_offense} = gettimeofday;
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
my @punishment = $self->{pbot}->{registry}->get_value('antiflood', 'chat_flood_punishment');
my $length = $punishment[$channel_data->{offenses} - 1 > $#punishment ? $#punishment : $channel_data->{offenses} - 1];
my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'chat_flood_punishment', $channel_data->{offenses} - 1);
$self->{pbot}->{chanops}->ban_user_timed("*!$user\@$host", $channel, $length);
$length = duration($length);
@ -381,8 +378,7 @@ sub check_flood {
$channel_data->{last_offense} = gettimeofday;
$self->{pbot}->{messagehistory}->{database}->update_channel_data($account, $channel, $channel_data);
my @punishment = $self->{pbot}->{registry}->get_value('antiflood', 'chat_flood_punishment');
my $length = $punishment[$channel_data->{offenses} - 1 > $#punishment ? $#punishment : $channel_data->{offenses} - 1];
my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'chat_flood_punishment', $channel_data->{offenses} - 1);
$self->{pbot}->{ignorelist}->{commands}->ignore_user("", "floodcontrol", "", "", "$nick!$user\@$host $channel $length");
$length = duration($length);
@ -396,8 +392,7 @@ sub check_flood {
$self->{nickflood}->{$account}->{changes} = $max_messages - 2; # allow 1 more change (to go back to original nick)
$self->{nickflood}->{$account}->{timestamp} = gettimeofday;
my @punishment = $self->{pbot}->{registry}->get_value('antiflood', 'nick_flood_punishment');
my $length = $punishment[$self->{nickflood}->{$account}->{offenses} - 1 > $#punishment ? $#punishment : $self->{nickflood}->{$account}->{offenses} - 1];
my $length = $self->{pbot}->{registry}->get_array_value('antiflood', 'nick_flood_punishment', $self->{nickflood}->{$account}->{offenses} - 1);
my @channels = $self->{pbot}->{messagehistory}->{database}->get_channels($account);
foreach my $chan (@channels) {
@ -741,7 +736,7 @@ sub adjust_offenses {
}
foreach my $account (keys %{ $self->{nickflood} }) {
if($self->{nickflood}->{$account}->{offenses} > 0 and gettimeofday - $self->{nickflood}->{$account}->{timestamp} >= 60 * 60 * 24) {
if($self->{nickflood}->{$account}->{offenses} and gettimeofday - $self->{nickflood}->{$account}->{timestamp} >= 60 * 60 * 24) {
$self->{nickflood}->{$account}->{offenses}--;
if($self->{nickflood}->{$account}->{offenses} == 0) {

View File

@ -138,6 +138,20 @@ sub get_value {
return undef;
}
sub get_array_value {
my ($self, $section, $item, $index) = @_;
if(exists $self->{registry}->hash->{$section} and exists $self->{registry}->hash->{$section}->{$item}) {
if($self->{registry}->hash->{$section}->{$item}->{type} eq 'array') {
my @array = split /\s*,\s*/, $self->{registry}->hash->{$section}->{$item}->{value};
return $array[$index >= $#array ? $#array : $index];
} else {
return $self->{registry}->hash->{$section}->{$item}->{value};
}
}
return undef;
}
sub add_trigger {
my ($self, $section, $item, $subref) = @_;
$self->{triggers}->{$section}->{$item} = $subref;

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 589,
BUILD_DATE => "2014-05-18",
BUILD_REVISION => 590,
BUILD_DATE => "2014-05-19",
};
1;