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

Improve handling of auto-op and op-commands on per-channel basis

Restore functionality to log out admins when they part/quit
Improve display of quit messages in log
This commit is contained in:
Pragmatic Software 2012-10-27 21:03:10 +00:00
parent f16dedf680
commit 208f89837f
6 changed files with 23 additions and 27 deletions

View File

@ -204,15 +204,15 @@ sub add_message {
sub check_flood {
my ($self, $channel, $nick, $user, $host, $text, $max_messages, $max_time, $mode) = @_;
my $mask = lc "$nick!$user\@$host";
my $now = gettimeofday;
$self->{pbot}->logger->log(sprintf("%-14s | %-65s | %s\n", $channel, $mask, $text));
$channel = lc $channel;
my $mask = lc "$nick!$user\@$host";
$self->{pbot}->logger->log(sprintf("%-14s | %-65s | %s\n", $channel eq $mask ? "QUIT" : $channel, $mask, $text));
$nick = lc $nick;
$user = lc $user;
$host = lc $host;
$channel = lc $channel;
return if $nick eq lc $self->{pbot}->botnick;

View File

@ -107,7 +107,7 @@ sub kick_user {
$self->{pbot}->logger->log("$nick!$user\@$host: invalid arguments to kick\n");
return "/msg $nick Usage: !kick <nick> <reason>";
}
unshift @{ $self->{pbot}->chanops->{op_commands} }, "kick $from $1 $2";
unshift @{ $self->{pbot}->chanops->{op_commands}->{$from} }, "kick $from $1 $2";
$self->{pbot}->chanops->gain_ops($from);
}

View File

@ -36,7 +36,7 @@ sub initialize {
$self->{pbot} = $pbot;
$self->{unban_timeout} = PBot::HashObject->new(pbot => $pbot, name => 'Unban Timeouts', filename => "$pbot->{data_dir}/unban_timeouts");
$self->{op_commands} = [];
$self->{op_commands} = {};
$self->{is_opped} = {};
$pbot->timer->register(sub { $self->check_opped_timeouts }, 10);
@ -47,13 +47,11 @@ sub gain_ops {
my $self = shift;
my $channel = shift;
if(not exists ${ $self->{is_opped} }{$channel}) {
if(not exists $self->{is_opped}->{$channel}) {
$self->{pbot}->conn->privmsg("chanserv", "op $channel");
$self->{is_opped}->{$channel}{timeout} = gettimeofday + 300; # assume we're going to be opped
$self->{pbot}->{irc}->flush_output_queue();
$self->{pbot}->{irc}->do_one_loop();
} else {
$self->perform_op_commands();
$self->perform_op_commands($channel);
}
}
@ -65,8 +63,10 @@ sub lose_ops {
sub perform_op_commands {
my $self = shift;
my $channel = shift;
$self->{pbot}->logger->log("Performing op commands...\n");
foreach my $command (@{ $self->{op_commands} }) {
foreach my $command (@{ $self->{op_commands}->{$channel} }) {
if($command =~ /^mode (.*?) (.*)/i) {
$self->{pbot}->conn->mode($1, $2);
$self->{pbot}->logger->log(" executing mode $1 $2\n");
@ -74,9 +74,7 @@ sub perform_op_commands {
$self->{pbot}->conn->kick($1, $2, $3) unless $1 =~ /\Q$self->{pbot}->botnick\E/i;
$self->{pbot}->logger->log(" executing kick on $1 $2 $3\n");
}
shift(@{ $self->{op_commands} });
$self->{pbot}->{irc}->flush_output_queue();
$self->{pbot}->{irc}->do_one_loop();
shift(@{ $self->{op_commands}->{$channel} });
}
$self->{pbot}->logger->log("Done.\n");
}
@ -84,7 +82,8 @@ sub perform_op_commands {
sub ban_user {
my $self = shift;
my ($mask, $channel) = @_;
unshift @{ $self->{op_commands} }, "mode $channel +b $mask";
unshift @{ $self->{op_commands}->{$channel} }, "mode $channel +b $mask";
$self->gain_ops($channel);
}
@ -94,7 +93,7 @@ sub unban_user {
$self->{pbot}->logger->log("Unbanning $mask\n");
delete $self->{unban_timeout}->hash->{$mask};
$self->{unban_timeout}->save_hash();
unshift @{ $self->{op_commands} }, "mode $channel -b $mask";
unshift @{ $self->{op_commands}->{$channel} }, "mode $channel -b $mask";
$self->gain_ops($channel);
}

View File

@ -145,7 +145,7 @@ sub on_mode {
if($mode eq "+o") {
$self->{pbot}->logger->log("$nick opped me in $channel\n");
$self->{pbot}->chanops->{is_opped}->{$channel}{timeout} = gettimeofday + 300; # 5 minutes
$self->{pbot}->chanops->perform_op_commands();
$self->{pbot}->chanops->perform_op_commands($channel);
}
elsif($mode eq "-o") {
$self->{pbot}->logger->log("$nick removed my ops in $channel\n");
@ -195,13 +195,12 @@ sub on_departure {
$self->{pbot}->antiflood->check_flood($channel, $nick, $user, $host, $text, 4, 60 * 30, $self->{pbot}->antiflood->{FLOOD_JOIN});
=cut
if(exists $admins{$nick} && exists $admins{$nick}{login}) {
my $admin = $self->{pbot}->admins->find_admin($channel, "$nick!$user\@$host");
if(defined $admin and $admin->{loggedin}) {
$self->{pbot}->logger->log("Whoops, $nick left while still logged in.\n");
$self->{pbot}->logger->log("Logged out $nick.\n");
delete $admins{$nick}{login};
delete $admin->{loggedin};
}
=cut
}
sub pbot {

View File

@ -42,7 +42,6 @@ sub initialize {
$self->{pbot} = $pbot;
}
=cut
sub paste_codepad {
my $text = join(' ', @_);
@ -61,9 +60,8 @@ sub paste_codepad {
return $response->request->uri;
}
=cut
sub paste_codepad {
sub paste_sprunge {
my $text = join(' ', @_);
$text =~ s/(.{120})\s/$1\n/g;
@ -157,7 +155,7 @@ sub process_line {
$result =~ s/\s+/ /g unless $preserve_whitespace;
if(length $result > $pbot->max_msg_len) {
my $link = paste_codepad("[" . (defined $from ? $from : "stdin") . "] <$nick> $text\n\n$original_result");
my $link = paste_sprunge("[" . (defined $from ? $from : "stdin") . "] <$nick> $text\n\n$original_result");
my $trunc = "... [truncated; see $link for full text.]";
$pbot->logger->log("Message truncated -- pasted to $link\n");

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 389,
BUILD_DATE => "2012-10-24",
BUILD_REVISION => 390,
BUILD_DATE => "2012-10-27",
};
1;