Reduce WHOIS queries when target joins multiple channels at once

This commit is contained in:
Pragmatic Software 2015-05-10 12:36:47 -07:00
parent b39123813c
commit 3776bef88a
2 changed files with 16 additions and 5 deletions

View File

@ -43,8 +43,9 @@ sub initialize {
$self->{NICKSERV_VALIDATED} = (1<<0); $self->{NICKSERV_VALIDATED} = (1<<0);
$self->{NEEDS_CHECKBAN} = (1<<1); $self->{NEEDS_CHECKBAN} = (1<<1);
$self->{channels} = {}; # per-channel statistics, e.g. for optimized tracking of last spoken nick for enter-abuse detection, etc $self->{channels} = {}; # per-channel statistics, e.g. for optimized tracking of last spoken nick for enter-abuse detection, etc
$self->{nickflood} = {}; # statistics to track nickchange flooding $self->{nickflood} = {}; # statistics to track nickchange flooding
$self->{whois_pending} = {}; # prevents multiple whois for nick joining multiple channels at once
my $filename = delete $conf{banwhitelist_file} // $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/ban_whitelist'; my $filename = delete $conf{banwhitelist_file} // $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/ban_whitelist';
$self->{ban_whitelist} = PBot::DualIndexHashObject->new(name => 'BanWhitelist', filename => $filename); $self->{ban_whitelist} = PBot::DualIndexHashObject->new(name => 'BanWhitelist', filename => $filename);
@ -77,6 +78,7 @@ sub initialize {
$self->{pbot}->{commands}->register(sub { return $self->whitelist(@_) }, "whitelist", 10); $self->{pbot}->{commands}->register(sub { return $self->whitelist(@_) }, "whitelist", 10);
$self->{pbot}->{event_dispatcher}->register_handler('irc.whoisaccount', sub { $self->on_whoisaccount(@_) }); $self->{pbot}->{event_dispatcher}->register_handler('irc.whoisaccount', sub { $self->on_whoisaccount(@_) });
$self->{pbot}->{event_dispatcher}->register_handler('irc.endofwhois', sub { $self->on_endofwhois(@_) });
} }
sub ban_whitelisted { sub ban_whitelisted {
@ -256,9 +258,11 @@ sub check_flood {
if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
# don't check for evasion on PART/KICK # don't check for evasion on PART/KICK
} elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { } elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
$self->{pbot}->{conn}->whois($nick); $self->{pbot}->{conn}->whois($nick) unless exists $self->{whois_pending}->{$nick};
$self->{whois_pending}->{$nick} = gettimeofday;
} else { } else {
$self->{pbot}->{conn}->whois($nick); $self->{pbot}->{conn}->whois($nick) unless exists $self->{whois_pending}->{$nick};
$self->{whois_pending}->{$nick} = gettimeofday;
$self->check_bans($account, $mask, $channel); $self->check_bans($account, $mask, $channel);
} }
} }
@ -750,11 +754,19 @@ sub check_nickserv_accounts {
} }
} }
sub on_endofwhois {
my ($self, $event_type, $event) = @_;
my $nick = $event->{event}->{args}[1];
delete $self->{whois_pending}->{$nick};
return 0;
}
sub on_whoisaccount { sub on_whoisaccount {
my ($self, $event_type, $event) = @_; my ($self, $event_type, $event) = @_;
my $nick = $event->{event}->{args}[1]; my $nick = $event->{event}->{args}[1];
my $account = lc $event->{event}->{args}[2]; my $account = lc $event->{event}->{args}[2];
delete $self->{whois_pending}->{$nick};
$self->{pbot}->{logger}->log("$nick is using NickServ account [$account]\n"); $self->{pbot}->{logger}->log("$nick is using NickServ account [$account]\n");
$self->check_nickserv_accounts($nick, $account); $self->check_nickserv_accounts($nick, $account);
return 0; return 0;

View File

@ -197,7 +197,6 @@ sub connect {
'whoiscountry', 'whoiscountry',
'whoischannels', 'whoischannels',
'whoisidle', 'whoisidle',
'endofwhois',
'motdstart', 'motdstart',
'endofmotd', 'endofmotd',
'away', 'away',