3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-29 23:39:24 +01:00

BanList: add banlist.mute_mode_char registry setting to configure MODE character used for muting

This commit is contained in:
Pragmatic Software 2020-05-31 02:39:33 -07:00
parent 273b87e52a
commit 91b7fa8558

View File

@ -29,6 +29,7 @@ sub initialize {
$self->{pbot}->{registry}->add_default('text', 'banlist', 'chanserv_ban_timeout', '604800'); $self->{pbot}->{registry}->add_default('text', 'banlist', 'chanserv_ban_timeout', '604800');
$self->{pbot}->{registry}->add_default('text', 'banlist', 'mute_timeout', '604800'); $self->{pbot}->{registry}->add_default('text', 'banlist', 'mute_timeout', '604800');
$self->{pbot}->{registry}->add_default('text', 'banlist', 'debug', '0'); $self->{pbot}->{registry}->add_default('text', 'banlist', 'debug', '0');
$self->{pbot}->{registry}->add_default('text', 'banlist', 'mute_mode_char', 'q');
$self->{pbot}->{commands}->register(sub { $self->cmd_banlist(@_) }, "banlist", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_banlist(@_) }, "banlist", 0);
$self->{pbot}->{commands}->register(sub { $self->cmd_checkban(@_) }, "checkban", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_checkban(@_) }, "checkban", 0);
@ -58,7 +59,7 @@ sub initialize {
$self->{quietlist}->load; $self->{quietlist}->load;
$self->enqueue_timeouts($self->{banlist}, 'b'); $self->enqueue_timeouts($self->{banlist}, 'b');
$self->enqueue_timeouts($self->{quietlist}, 'q'); $self->enqueue_timeouts($self->{quietlist}, $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char'));
$self->{ban_queue} = {}; $self->{ban_queue} = {};
$self->{unban_queue} = {}; $self->{unban_queue} = {};
@ -148,7 +149,7 @@ sub cmd_checkmute {
$channel = $context->{from} if not defined $channel; $channel = $context->{from} if not defined $channel;
return "Please specify a channel." if $channel !~ /^#/; return "Please specify a channel." if $channel !~ /^#/;
return $self->checkban($channel, 'q', $target); return $self->checkban($channel, $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char'), $target);
} }
sub get_banlist { sub get_banlist {
@ -156,7 +157,15 @@ sub get_banlist {
my $channel = lc $event->{event}->{args}[1]; my $channel = lc $event->{event}->{args}[1];
$self->{pbot}->{logger}->log("Retrieving banlist for $channel.\n"); $self->{pbot}->{logger}->log("Retrieving banlist for $channel.\n");
delete $self->{temp_banlist}; delete $self->{temp_banlist};
$event->{conn}->sl("mode $channel +bq");
my $mute_char = $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char');
if ($mute_char eq 'b') {
$event->{conn}->sl("mode $channel +b");
} else {
$event->{conn}->sl("mode $channel +b$mute_char");
}
return 0; return 0;
} }
@ -184,7 +193,8 @@ sub on_quietlist_entry {
my $ago = concise ago(gettimeofday - $timestamp); my $ago = concise ago(gettimeofday - $timestamp);
$self->{pbot}->{logger}->log("Ban List: [quietlist entry] $channel: $target quieted by $source $ago.\n"); $self->{pbot}->{logger}->log("Ban List: [quietlist entry] $channel: $target quieted by $source $ago.\n");
$self->{temp_banlist}->{$channel}->{'+q'}->{$target} = [$source, $timestamp]; my $mute_char = $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char');
$self->{temp_banlist}->{$channel}->{"+$mute_char"}->{$target} = [$source, $timestamp];
return 0; return 0;
} }
@ -238,10 +248,11 @@ sub compare_quietlist {
my $channel = lc $event->{event}->{args}[1]; my $channel = lc $event->{event}->{args}[1];
$self->{pbot}->{logger}->log("Finalizing quiet list for $channel\n"); $self->{pbot}->{logger}->log("Finalizing quiet list for $channel\n");
my $mute_char = $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char');
# first check for saved quiets no longer in channel # first check for saved quiets no longer in channel
foreach my $mask ($self->{quietlist}->get_keys($channel)) { foreach my $mask ($self->{quietlist}->get_keys($channel)) {
if (not exists $self->{temp_banlist}->{$channel}->{'+q'}->{$mask}) { if (not exists $self->{temp_banlist}->{$channel}->{"+$mute_char"}->{$mask}) {
$self->{pbot}->{logger}->log("BanList: Saved quiet +q $mask no longer exists in $channel.\n"); $self->{pbot}->{logger}->log("BanList: Saved quiet +q $mask no longer exists in $channel.\n");
# TODO option to restore quiet # TODO option to restore quiet
$self->{quietlist}->remove($channel, $mask, undef, 1); $self->{quietlist}->remove($channel, $mask, undef, 1);
@ -250,15 +261,15 @@ sub compare_quietlist {
} }
# add channel bans to saved bans # add channel bans to saved bans
foreach my $mask (keys %{$self->{temp_banlist}->{$channel}->{'+q'}}) { foreach my $mask (keys %{$self->{temp_banlist}->{$channel}->{"+$mute_char"}}) {
my $data = $self->{quietlist}->get_data($channel, $mask); my $data = $self->{quietlist}->get_data($channel, $mask);
$data->{owner} = $self->{temp_banlist}->{$channel}->{'+q'}->{$mask}->[0]; $data->{owner} = $self->{temp_banlist}->{$channel}->{"+$mute_char"}->{$mask}->[0];
$data->{timestamp} = $self->{temp_banlist}->{$channel}->{'+q'}->{$mask}->[1]; $data->{timestamp} = $self->{temp_banlist}->{$channel}->{"+$mute_char"}->{$mask}->[1];
$self->{quietlist}->add($channel, $mask, $data, 1); $self->{quietlist}->add($channel, $mask, $data, 1);
} }
$self->{quietlist}->save if keys %{$self->{temp_banlist}->{$channel}->{'+q'}}; $self->{quietlist}->save if keys %{$self->{temp_banlist}->{$channel}->{"+$mute_char"}};
delete $self->{temp_banlist}->{$channel}->{'+q'}; delete $self->{temp_banlist}->{$channel}->{"+$mute_char"};
} }
sub track_mode { sub track_mode {
@ -269,8 +280,10 @@ sub track_mode {
$channel = lc $channel; $channel = lc $channel;
$mask = lc $mask; $mask = lc $mask;
if ($mode eq "+b" or $mode eq "+q") { my $mute_char = $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char');
$self->{pbot}->{logger}->log("Ban List: $mask " . ($mode eq '+b' ? 'banned' : 'quieted') . " by $source in $channel.\n");
if ($mode eq "+b" or $mode eq "+$mute_char") {
$self->{pbot}->{logger}->log("Ban List: $mask " . ($mode eq '+b' ? 'banned' : 'muted') . " by $source in $channel.\n");
my $data = { my $data = {
owner => $source, owner => $source,
@ -279,13 +292,13 @@ sub track_mode {
if ($mode eq "+b") { if ($mode eq "+b") {
$self->{banlist}->add($channel, $mask, $data); $self->{banlist}->add($channel, $mask, $data);
} elsif ($mode eq "+q") { } elsif ($mode eq "+$mute_char") {
$self->{quietlist}->add($channel, $mask, $data); $self->{quietlist}->add($channel, $mask, $data);
} }
$self->{pbot}->{antiflood}->devalidate_accounts($mask, $channel); $self->{pbot}->{antiflood}->devalidate_accounts($mask, $channel);
} elsif ($mode eq "-b" or $mode eq "-q") { } elsif ($mode eq "-b" or $mode eq "-$mute_char") {
$self->{pbot}->{logger}->log("Ban List: $mask " . ($mode eq '-b' ? 'unbanned' : 'unquieted') . " by $source in $channel.\n"); $self->{pbot}->{logger}->log("Ban List: $mask " . ($mode eq '-b' ? 'unbanned' : 'unmuted') . " by $source in $channel.\n");
if ($mode eq "-b") { if ($mode eq "-b") {
$self->{banlist}->remove($channel, $mask); $self->{banlist}->remove($channel, $mask);
@ -294,7 +307,7 @@ sub track_mode {
# freenode strips channel forwards from unban result if no ban exists with a channel forward # freenode strips channel forwards from unban result if no ban exists with a channel forward
$self->{banlist}->remove($channel, "$mask\$##stop_join_flood"); $self->{banlist}->remove($channel, "$mask\$##stop_join_flood");
$self->{pbot}->{timer}->dequeue_event(lc "unban $channel $mask\$##stop_join_flood"); $self->{pbot}->{timer}->dequeue_event(lc "unban $channel $mask\$##stop_join_flood");
} elsif ($mode eq "-q") { } elsif ($mode eq "-$mute_char") {
$self->{quietlist}->remove($channel, $mask); $self->{quietlist}->remove($channel, $mask);
$self->{pbot}->{timer}->dequeue_event("unmute $channel $mask"); $self->{pbot}->{timer}->dequeue_event("unmute $channel $mask");
} }
@ -338,7 +351,7 @@ sub track_mode {
} }
} }
} }
} elsif ($mode eq "+q") { } elsif ($mode eq "+$mute_char") {
if (lc $nick ne lc $self->{pbot}->{registry}->get_value('irc', 'botnick')) { if (lc $nick ne lc $self->{pbot}->{registry}->get_value('irc', 'botnick')) {
$self->{pbot}->{logger}->log("WEIRD MUTE THING $nick...\n"); $self->{pbot}->{logger}->log("WEIRD MUTE THING $nick...\n");
if ($self->{quietlist}->exists($channel, $mask)) { if ($self->{quietlist}->exists($channel, $mask)) {
@ -352,7 +365,7 @@ sub track_mode {
timestamp => gettimeofday, timestamp => gettimeofday,
}; };
$self->{quietlist}->add($channel, $mask, $data); $self->{quietlist}->add($channel, $mask, $data);
$self->enqueue_unban($channel, 'q', $mask, $self->{pbot}->{registry}->get_value('banlist', 'mute_timeout')); $self->enqueue_unban($channel, $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char'), $mask, $self->{pbot}->{registry}->get_value('banlist', 'mute_timeout'));
} }
} }
} }
@ -452,8 +465,8 @@ sub get_baninfo {
my ($nick, $user, $host) = $mask =~ m/([^!]+)!([^@]+)@(.*)/; my ($nick, $user, $host) = $mask =~ m/([^!]+)!([^@]+)@(.*)/;
my @lists = ( my @lists = (
[ 'b', $self->{banlist} ], [ 'b', $self->{banlist} ],
[ 'q', $self->{quietlist} ], [ $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char'), $self->{quietlist} ],
); );
foreach my $entry (@lists) { foreach my $entry (@lists) {
@ -532,7 +545,7 @@ sub ban_user_timed {
if ($mode eq 'b') { if ($mode eq 'b') {
$self->{banlist}->add($channel, $mask, $data); $self->{banlist}->add($channel, $mask, $data);
} elsif ($mode eq 'q') { } elsif ($mode eq $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char')) {
$self->{quietlist}->add($channel, $mask, $data); $self->{quietlist}->add($channel, $mask, $data);
} }
@ -552,7 +565,7 @@ sub checkban {
if ($mode eq 'b') { if ($mode eq 'b') {
$data = $self->{banlist}->get_data($channel, $mask); $data = $self->{banlist}->get_data($channel, $mask);
} elsif ($mode eq 'q') { } elsif ($mode eq $self->{pbot}->{registry}->get_value('banlist', 'mute_mode_char')) {
$data = $self->{quietlist}->get_data($channel, $mask); $data = $self->{quietlist}->get_data($channel, $mask);
} }