3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 19:22:40 +01:00

Add default handler for unhandled IRC events; ignore certain IRC events; improve handling of chan-op requests

This commit is contained in:
Pragmatic Software 2014-08-11 07:34:30 +00:00
parent c40e34b3a1
commit 068c6a0559
4 changed files with 56 additions and 8 deletions

View File

@ -37,6 +37,7 @@ sub initialize {
$self->{op_commands} = {}; $self->{op_commands} = {};
$self->{is_opped} = {}; $self->{is_opped} = {};
$self->{op_requested} = {};
$self->{commands} = PBot::ChanOpCommands->new(pbot => $self->{pbot}); $self->{commands} = PBot::ChanOpCommands->new(pbot => $self->{pbot});
@ -50,9 +51,12 @@ sub gain_ops {
my $self = shift; my $self = shift;
my $channel = shift; my $channel = shift;
return if exists $self->{op_requested}->{$channel};
return if not exists $self->{pbot}->{channels}->{channels}->hash->{$channel} or not $self->{pbot}->{channels}->{channels}->hash->{$channel}{chanop};
if(not exists $self->{is_opped}->{$channel}) { if(not exists $self->{is_opped}->{$channel}) {
$self->{pbot}->{conn}->privmsg("chanserv", "op $channel"); $self->{pbot}->{conn}->privmsg("chanserv", "op $channel");
$self->{is_opped}->{$channel}{timeout} = gettimeofday + $self->{pbot}->{registry}->get_value('general', 'deop_timeout'); # assume we're going to be opped $self->{op_requested}->{$channel} = scalar gettimeofday;
} else { } else {
$self->perform_op_commands($channel); $self->perform_op_commands($channel);
} }
@ -78,7 +82,7 @@ sub perform_op_commands {
while(my $command = shift @{ $self->{op_commands}->{$channel} }) { while(my $command = shift @{ $self->{op_commands}->{$channel} }) {
if($command =~ /^mode (.*?) (.*)/i) { if($command =~ /^mode (.*?) (.*)/i) {
$self->{pbot}->{conn}->mode($1, $2); $self->{pbot}->{conn}->mode($1, $2);
$self->{pbot}->{logger}->log(" executing mode $1 $2\n"); $self->{pbot}->{logger}->log(" executing mode [$1] [$2]\n");
} elsif($command =~ /^kick (.*?) (.*?) (.*)/i) { } elsif($command =~ /^kick (.*?) (.*?) (.*)/i) {
$self->{pbot}->{conn}->kick($1, $2, $3) unless $1 =~ /\Q$botnick\E/i; $self->{pbot}->{conn}->kick($1, $2, $3) unless $1 =~ /\Q$botnick\E/i;
$self->{pbot}->{logger}->log(" executing kick on $1 $2 $3\n"); $self->{pbot}->{logger}->log(" executing kick on $1 $2 $3\n");
@ -145,6 +149,14 @@ sub check_opped_timeouts {
# $self->{pbot}->{logger}->log("deop $channel in $timediff seconds\n"); # $self->{pbot}->{logger}->log("deop $channel in $timediff seconds\n");
} }
} }
foreach my $channel (keys %{ $self->{op_requested} }) {
if ($now - $self->{op_requested}->{$channel} > 60 * 5) {
$self->{pbot}->{logger}->log("5 minutes since OP request for $channel and no OP yet; trying again ...\n");
delete $self->{op_requested}->{$channel};
$self->gain_ops($channel);
}
}
} }
1; 1;

View File

@ -10,6 +10,7 @@ use strict;
use Carp(); use Carp();
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use Data::Dumper;
sub new { sub new {
if(ref($_[1]) eq 'HASH') { if(ref($_[1]) eq 'HASH') {
@ -32,8 +33,14 @@ sub initialize {
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
} }
# IRC related subroutines sub default_handler {
################################################# my ($self, $conn, $event) = @_;
if ($self->{pbot}->{registry}->get_value('irc', 'log_default_handler')) {
my $dump = Dumper $event;
$self->{pbot}->{logger}->log($dump);
}
}
sub on_connect { sub on_connect {
my ($self, $conn) = @_; my ($self, $conn) = @_;
@ -58,6 +65,16 @@ sub on_init {
$self->{pbot}->{logger}->log("*** @args\n"); $self->{pbot}->{logger}->log("*** @args\n");
} }
sub on_motd {
my ($self, $conn, $event) = @_;
if ($self->{pbot}->{registry}->get_value('irc', 'show_motd')) {
my $server = $event->{from};
my $msg = $event->{args}[1];
$self->{pbot}->{logger}->log("MOTD from $server :: $msg\n");
}
}
sub on_public { sub on_public {
my ($self, $conn, $event) = @_; my ($self, $conn, $event) = @_;
@ -145,6 +162,7 @@ sub on_mode {
if($mode eq "+o") { if($mode eq "+o") {
$self->{pbot}->{logger}->log("$nick opped me in $channel\n"); $self->{pbot}->{logger}->log("$nick opped me in $channel\n");
$self->{pbot}->{chanops}->{is_opped}->{$channel}{timeout} = gettimeofday + $self->{pbot}->{registry}->get_value('general', 'deop_timeout');; $self->{pbot}->{chanops}->{is_opped}->{$channel}{timeout} = gettimeofday + $self->{pbot}->{registry}->get_value('general', 'deop_timeout');;
delete $self->{pbot}->{chanops}->{op_requested}->{$channel};
$self->{pbot}->{chanops}->perform_op_commands($channel); $self->{pbot}->{chanops}->perform_op_commands($channel);
} }
elsif($mode eq "-o") { elsif($mode eq "-o") {
@ -159,8 +177,10 @@ 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}->hash->{$channel}->{$target}{timeout} = gettimeofday + $self->{pbot}->{registry}->get_value('bantracker', 'chanserv_ban_timeout'); if (exists $self->{pbot}->{channels}->{channels}->hash->{$channel} and $self->{pbot}->{channels}->{channels}->hash->{$channel}{chanop}) {
$self->{pbot}->{chanops}->{unban_timeout}->save; $self->{pbot}->{chanops}->{unban_timeout}->hash->{$channel}->{$target}{timeout} = gettimeofday + $self->{pbot}->{registry}->get_value('bantracker', 'chanserv_ban_timeout');
$self->{pbot}->{chanops}->{unban_timeout}->save;
}
} }
} }
elsif($mode eq "+e" && $channel eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { elsif($mode eq "+e" && $channel eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) {

View File

@ -78,6 +78,7 @@ sub initialize {
$self->{registry}->add_default('text', 'general', 'trigger', delete $conf{trigger} // '!'); $self->{registry}->add_default('text', 'general', 'trigger', delete $conf{trigger} // '!');
$self->{registry}->add_default('text', 'irc', 'debug', delete $conf{irc_debug} // 0); $self->{registry}->add_default('text', 'irc', 'debug', delete $conf{irc_debug} // 0);
$self->{registry}->add_default('text', 'irc', 'show_motd', delete $conf{show_motd} // 1);
$self->{registry}->add_default('text', 'irc', 'max_msg_len', delete $conf{max_msg_len} // 425); $self->{registry}->add_default('text', 'irc', 'max_msg_len', delete $conf{max_msg_len} // 425);
$self->{registry}->add_default('text', 'irc', 'ircserver', delete $conf{ircserver} // "irc.freenode.net"); $self->{registry}->add_default('text', 'irc', 'ircserver', delete $conf{ircserver} // "irc.freenode.net");
$self->{registry}->add_default('text', 'irc', 'port', delete $conf{port} // 6667); $self->{registry}->add_default('text', 'irc', 'port', delete $conf{port} // 6667);
@ -88,6 +89,7 @@ sub initialize {
$self->{registry}->add_default('text', 'irc', 'username', delete $conf{username} // "pbot3"); $self->{registry}->add_default('text', 'irc', 'username', delete $conf{username} // "pbot3");
$self->{registry}->add_default('text', 'irc', 'ircname', delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/"); $self->{registry}->add_default('text', 'irc', 'ircname', delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/");
$self->{registry}->add_default('text', 'irc', 'identify_password', delete $conf{identify_password} // 'none'); $self->{registry}->add_default('text', 'irc', 'identify_password', delete $conf{identify_password} // 'none');
$self->{registry}->add_default('text', 'irc', 'log_default_handler', 1);
$self->{registry}->set('irc', 'SSL_ca_file', 'private', 1); $self->{registry}->set('irc', 'SSL_ca_file', 'private', 1);
$self->{registry}->set('irc', 'SSL_ca_path', 'private', 1); $self->{registry}->set('irc', 'SSL_ca_path', 'private', 1);
@ -167,10 +169,13 @@ sub connect {
$self->{connected} = 1; $self->{connected} = 1;
#set up default handlers for the IRC engine #set up handlers for the IRC engine
$self->{conn}->add_default_handler(sub { $self->{irchandlers}->default_handler(@_) }, 1);
$self->{conn}->add_handler([ 251,252,253,254,302,255 ], sub { $self->{irchandlers}->on_init(@_) }); $self->{conn}->add_handler([ 251,252,253,254,302,255 ], sub { $self->{irchandlers}->on_init(@_) });
$self->{conn}->add_handler(376 , sub { $self->{irchandlers}->on_connect(@_) }); $self->{conn}->add_handler(376 , sub { $self->{irchandlers}->on_connect(@_) });
$self->{conn}->add_handler('disconnect' , sub { $self->{irchandlers}->on_disconnect(@_) }); $self->{conn}->add_handler('disconnect' , sub { $self->{irchandlers}->on_disconnect(@_) });
$self->{conn}->add_handler('motd' , sub { $self->{irchandlers}->on_motd(@_) });
$self->{conn}->add_handler('notice' , sub { $self->{irchandlers}->on_notice(@_) }); $self->{conn}->add_handler('notice' , sub { $self->{irchandlers}->on_notice(@_) });
$self->{conn}->add_handler('caction' , sub { $self->{irchandlers}->on_action(@_) }); $self->{conn}->add_handler('caction' , sub { $self->{irchandlers}->on_action(@_) });
$self->{conn}->add_handler('public' , sub { $self->{irchandlers}->on_public(@_) }); $self->{conn}->add_handler('public' , sub { $self->{irchandlers}->on_public(@_) });
@ -188,6 +193,17 @@ sub connect {
$self->{conn}->add_handler(728 , sub { $self->{bantracker}->on_quietlist_entry(@_) }); $self->{conn}->add_handler(728 , sub { $self->{bantracker}->on_quietlist_entry(@_) });
$self->{conn}->add_handler('bannickchange' , sub { $self->{irchandlers}->on_bannickchange(@_) }); $self->{conn}->add_handler('bannickchange' , sub { $self->{irchandlers}->on_bannickchange(@_) });
$self->{conn}->add_handler('notregistered' , sub { $self->{irchandlers}->on_notregistered(@_) }); $self->{conn}->add_handler('notregistered' , sub { $self->{irchandlers}->on_notregistered(@_) });
# ignore these events
$self->{conn}->add_handler(['whoisuser',
'whoisserver',
'whoiscountry',
'whoischannels',
'whoisidle',
'endofwhois',
'motdstart',
'away',
'endofbanlist'], sub {});
} }
#main loop #main loop

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 => 774, BUILD_REVISION => 775,
BUILD_DATE => "2014-08-11", BUILD_DATE => "2014-08-11",
}; };