2010-03-17 07:36:54 +01:00
|
|
|
# File: IRCHandlers.pm
|
2010-03-22 08:33:44 +01:00
|
|
|
# Author: pragma_
|
2010-03-17 07:36:54 +01:00
|
|
|
#
|
|
|
|
# Purpose: Subroutines to handle IRC events
|
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2010-03-17 07:36:54 +01:00
|
|
|
package PBot::IRCHandlers;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2010-03-23 19:24:02 +01:00
|
|
|
use Carp();
|
|
|
|
use Time::HiRes qw(gettimeofday);
|
2014-08-11 09:34:30 +02:00
|
|
|
use Data::Dumper;
|
2018-02-28 20:13:56 +01:00
|
|
|
$Data::Dumper::Sortkeys = 1;
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub new {
|
2018-08-03 21:31:45 +02:00
|
|
|
if (ref($_[1]) eq 'HASH') {
|
2014-11-01 01:15:21 +01:00
|
|
|
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference");
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
my ($class, %conf) = @_;
|
|
|
|
|
|
|
|
my $self = bless {}, $class;
|
|
|
|
$self->initialize(%conf);
|
|
|
|
return $self;
|
|
|
|
}
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub initialize {
|
|
|
|
my ($self, %conf) = @_;
|
|
|
|
|
2014-11-01 01:15:21 +01:00
|
|
|
$self->{pbot} = delete $conf{pbot};
|
|
|
|
Carp::croak("Missing pbot parameter to " . __FILE__) if not defined $self->{pbot};
|
|
|
|
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.welcome', sub { $self->on_connect(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.disconnect', sub { $self->on_disconnect(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.motd', sub { $self->on_motd(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.notice', sub { $self->on_notice(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_action(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.msg', sub { $self->on_msg(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.mode', sub { $self->on_mode(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.part', sub { $self->on_departure(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.join', sub { $self->on_join(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.kick', sub { $self->on_kick(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.quit', sub { $self->on_departure(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.nick', sub { $self->on_nickchange(@_) });
|
2015-01-11 00:56:43 +01:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.nicknameinuse', sub { $self->on_nicknameinuse(@_) });
|
2016-07-01 22:01:34 +02:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.invite', sub { $self->on_invite(@_) });
|
2016-08-28 12:49:27 +02:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.cap', sub { $self->on_cap(@_) });
|
2017-05-21 11:20:44 +02:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.map', sub { $self->on_map(@_) });
|
2017-08-02 06:35:56 +02:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.whospcrpl', sub { $self->on_whospcrpl(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.endofwho', sub { $self->on_endofwho(@_) });
|
2018-08-06 07:47:38 +02:00
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.channelmodeis', sub { $self->on_channelmodeis(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.topic', sub { $self->on_topic(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.topicinfo', sub { $self->on_topicinfo(@_) });
|
2017-08-02 06:35:56 +02:00
|
|
|
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('pbot.join', sub { $self->on_self_join(@_) });
|
|
|
|
$self->{pbot}->{event_dispatcher}->register_handler('pbot.part', sub { $self->on_self_part(@_) });
|
|
|
|
|
|
|
|
$self->{pbot}->{timer}->register(sub { $self->check_pending_whos }, 10);
|
2010-03-22 08:33:44 +01:00
|
|
|
}
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2014-08-11 09:34:30 +02:00
|
|
|
sub default_handler {
|
|
|
|
my ($self, $conn, $event) = @_;
|
|
|
|
|
2018-08-03 21:31:45 +02:00
|
|
|
if (not defined $self->{pbot}->{event_dispatcher}->dispatch_event("irc.$event->{type}", { conn => $conn, event => $event })) {
|
2014-11-01 01:15:21 +01:00
|
|
|
if ($self->{pbot}->{registry}->get_value('irc', 'log_default_handler')) {
|
2015-09-07 07:04:21 +02:00
|
|
|
$self->{pbot}->{logger}->log(Dumper $event);
|
2014-11-01 01:15:21 +01:00
|
|
|
}
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_init {
|
2010-03-22 08:33:44 +01:00
|
|
|
my ($self, $conn, $event) = @_;
|
2010-03-17 07:36:54 +01:00
|
|
|
my (@args) = ($event->args);
|
|
|
|
shift (@args);
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("*** @args\n");
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
2014-11-01 01:15:21 +01:00
|
|
|
sub on_connect {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
$self->{pbot}->{logger}->log("Connected!\n");
|
|
|
|
$event->{conn}->{connected} = 1;
|
2015-01-11 00:56:43 +01:00
|
|
|
|
2016-08-28 12:49:27 +02:00
|
|
|
$self->{pbot}->{logger}->log("Requesting account-notify and extended-join . . .\n");
|
|
|
|
$event->{conn}->sl("CAP REQ :account-notify extended-join");
|
|
|
|
|
2015-01-11 00:56:43 +01:00
|
|
|
$self->{pbot}->{logger}->log("Identifying with NickServ . . .\n");
|
|
|
|
$event->{conn}->privmsg("nickserv", "identify " . $self->{pbot}->{registry}->get_value('irc', 'botnick') . ' ' . $self->{pbot}->{registry}->get_value('irc', 'identify_password'));
|
|
|
|
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_disconnect {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
$self->{pbot}->{logger}->log("Disconnected...\n");
|
|
|
|
$self->{pbot}->{connected} = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-11 09:34:30 +02:00
|
|
|
sub on_motd {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
2014-08-11 09:34:30 +02:00
|
|
|
|
|
|
|
if ($self->{pbot}->{registry}->get_value('irc', 'show_motd')) {
|
2014-11-01 01:15:21 +01:00
|
|
|
my $server = $event->{event}->{from};
|
|
|
|
my $msg = $event->{event}->{args}[1];
|
2014-08-11 09:34:30 +02:00
|
|
|
$self->{pbot}->{logger}->log("MOTD from $server :: $msg\n");
|
|
|
|
}
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
2014-08-11 09:34:30 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 06:35:56 +02:00
|
|
|
sub on_self_join {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
$self->send_who($event->{channel});
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_self_part {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-17 07:36:54 +01:00
|
|
|
sub on_public {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2014-11-01 01:15:21 +01:00
|
|
|
my $from = $event->{event}->{to}[0];
|
|
|
|
my $nick = $event->{event}->nick;
|
|
|
|
my $user = $event->{event}->user;
|
|
|
|
my $host = $event->{event}->host;
|
|
|
|
my $text = $event->{event}->{args}[0];
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2017-06-18 12:40:51 +02:00
|
|
|
($nick, $user, $host) = $self->normalize_hostmask($nick, $user, $host);
|
|
|
|
|
2015-09-08 10:37:34 +02:00
|
|
|
$event->{interpreted} = $self->{pbot}->{interpreter}->process_line($from, $nick, $user, $host, $text);
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub on_msg {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my ($nick, $host) = ($event->{event}->nick, $event->{event}->host);
|
|
|
|
my $text = $event->{event}->{args}[0];
|
2015-03-27 21:00:43 +01:00
|
|
|
|
2014-05-17 22:08:19 +02:00
|
|
|
my $bot_trigger = $self->{pbot}->{registry}->get_value('general', 'trigger');
|
2015-03-27 21:00:43 +01:00
|
|
|
my $bot_nick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2015-03-27 21:00:43 +01:00
|
|
|
$text =~ s/^$bot_trigger?\s*(.*)/$bot_nick $1/;
|
2014-11-01 01:15:21 +01:00
|
|
|
$event->{event}->{to}[0] = $nick;
|
|
|
|
$event->{event}->{args}[0] = $text;
|
|
|
|
$self->on_public($event_type, $event);
|
|
|
|
return 0;
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub on_notice {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
2015-09-04 05:46:12 +02:00
|
|
|
my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host);
|
2014-11-01 01:15:21 +01:00
|
|
|
my $text = $event->{event}->{args}[0];
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2015-09-04 05:46:12 +02:00
|
|
|
$self->{pbot}->{logger}->log("Received NOTICE from $nick!$user\@$host to $event->{event}->{to}[0] '$text'\n");
|
2015-09-07 07:04:21 +02:00
|
|
|
|
|
|
|
return 0 if not length $host;
|
2015-01-11 00:56:43 +01:00
|
|
|
|
2018-08-03 21:31:45 +02:00
|
|
|
if ($nick eq 'NickServ') {
|
|
|
|
if ($text =~ m/This nickname is registered/) {
|
2015-01-11 00:56:43 +01:00
|
|
|
$self->{pbot}->{logger}->log("Identifying with NickServ . . .\n");
|
|
|
|
$event->{conn}->privmsg("nickserv", "identify " . $self->{pbot}->{registry}->get_value('irc', 'identify_password'));
|
2018-08-03 21:31:45 +02:00
|
|
|
} elsif ($text =~ m/You are now identified/) {
|
2015-01-11 00:56:43 +01:00
|
|
|
$event->{conn}->nick($self->{pbot}->{registry}->get_value('irc', 'botnick'));
|
2018-08-03 21:31:45 +02:00
|
|
|
} elsif ($text =~ m/has been ghosted/) {
|
2015-01-11 00:56:43 +01:00
|
|
|
$event->{conn}->nick($self->{pbot}->{registry}->get_value('irc', 'botnick'));
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
2015-09-04 05:46:12 +02:00
|
|
|
} else {
|
|
|
|
if ($event->{event}->{to}[0] eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) {
|
|
|
|
$event->{event}->{to}[0] = $nick;
|
|
|
|
}
|
|
|
|
$self->on_public($event_type, $event);
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub on_action {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
2013-06-04 19:09:30 +02:00
|
|
|
|
2014-11-01 01:15:21 +01:00
|
|
|
$event->{event}->{args}[0] = "/me " . $event->{event}->{args}[0];
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2014-11-01 01:15:21 +01:00
|
|
|
$self->on_public($event_type, $event);
|
|
|
|
return 0;
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 07:47:38 +02:00
|
|
|
# FIXME: on_mode doesn't handle chanmodes that have parameters, e.g. +l
|
|
|
|
|
2010-03-17 07:36:54 +01:00
|
|
|
sub on_mode {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host);
|
|
|
|
my $mode_string = $event->{event}->{args}[0];
|
|
|
|
my $channel = $event->{event}->{to}[0];
|
2010-03-17 07:36:54 +01:00
|
|
|
$channel = lc $channel;
|
|
|
|
|
2017-06-18 12:40:51 +02:00
|
|
|
($nick, $user, $host) = $self->normalize_hostmask($nick, $user, $host);
|
|
|
|
|
2018-08-03 21:31:45 +02:00
|
|
|
my ($mode, $mode_char, $modifier);
|
2011-02-13 10:05:48 +01:00
|
|
|
my $i = 0;
|
|
|
|
my $target;
|
2011-02-13 06:07:02 +01:00
|
|
|
|
2018-08-06 07:47:38 +02:00
|
|
|
while ($mode_string =~ m/(.)/g) {
|
2011-02-13 10:05:48 +01:00
|
|
|
my $char = $1;
|
2011-02-13 06:07:02 +01:00
|
|
|
|
2018-08-03 21:31:45 +02:00
|
|
|
if ($char eq '-' or $char eq '+') {
|
2011-02-13 10:05:48 +01:00
|
|
|
$modifier = $char;
|
|
|
|
next;
|
|
|
|
}
|
2011-02-13 06:07:02 +01:00
|
|
|
|
2011-02-13 10:05:48 +01:00
|
|
|
$mode = $modifier . $char;
|
2018-08-03 21:31:45 +02:00
|
|
|
$mode_char = $char;
|
2014-11-01 01:15:21 +01:00
|
|
|
$target = $event->{event}->{args}[++$i];
|
2011-02-13 06:07:02 +01:00
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("Got mode: source: $nick!$user\@$host, mode: $mode, target: " . (defined $target ? $target : "(undef)") . ", channel: $channel\n");
|
2011-02-13 06:07:02 +01:00
|
|
|
|
2018-08-03 21:31:45 +02:00
|
|
|
if ($mode eq "-b" or $mode eq "+b" or $mode eq "-q" or $mode eq "+q") {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{bantracker}->track_mode("$nick!$user\@$host", $mode, $target, $channel);
|
2011-02-13 06:07:02 +01:00
|
|
|
}
|
2011-02-13 10:05:48 +01:00
|
|
|
|
2018-08-06 07:47:38 +02:00
|
|
|
if (defined $target and length $target) {
|
2018-08-03 21:31:45 +02:00
|
|
|
if ($modifier eq '-') {
|
|
|
|
$self->{pbot}->{nicklist}->delete_meta($channel, $target, "+$mode_char");
|
|
|
|
} else {
|
|
|
|
$self->{pbot}->{nicklist}->set_meta($channel, $target, $mode, 1);
|
|
|
|
}
|
2018-08-06 07:47:38 +02:00
|
|
|
} else {
|
|
|
|
my $modes = $self->{pbot}->{channels}->get_meta($channel, 'MODE');
|
|
|
|
if (defined $modes) {
|
|
|
|
if ($modifier eq '+') {
|
|
|
|
$modes = '+' if not length $modes;
|
|
|
|
$modes .= $mode_char;
|
|
|
|
} else {
|
|
|
|
$modes =~ s/\Q$mode_char\E//g;
|
|
|
|
}
|
|
|
|
$self->{pbot}->{channels}->{channels}->set($channel, 'MODE', $modes, 1);
|
|
|
|
}
|
2018-08-03 21:31:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $target && $target eq $event->{conn}->nick) { # bot targeted
|
|
|
|
if ($mode eq "+o") {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick opped me in $channel\n");
|
2017-08-02 06:35:56 +02:00
|
|
|
my $timeout = $self->{pbot}->{registry}->get_value($channel, 'deop_timeout') // $self->{pbot}->{registry}->get_value('general', 'deop_timeout');
|
|
|
|
$self->{pbot}->{chanops}->{is_opped}->{$channel}{timeout} = gettimeofday + $timeout;
|
2014-08-11 09:34:30 +02:00
|
|
|
delete $self->{pbot}->{chanops}->{op_requested}->{$channel};
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{chanops}->perform_op_commands($channel);
|
2011-02-13 10:05:48 +01:00
|
|
|
}
|
2018-08-03 21:31:45 +02:00
|
|
|
elsif ($mode eq "-o") {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick removed my ops in $channel\n");
|
|
|
|
delete $self->{pbot}->{chanops}->{is_opped}->{$channel};
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
2018-08-03 21:31:45 +02:00
|
|
|
elsif ($mode eq "+b") {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("Got banned in $channel, attempting unban.");
|
2014-11-01 01:15:21 +01:00
|
|
|
$event->{conn}->privmsg("chanserv", "unban $channel");
|
2011-02-13 10:05:48 +01:00
|
|
|
}
|
2011-02-13 06:07:02 +01:00
|
|
|
}
|
2011-02-13 10:05:48 +01:00
|
|
|
else { # bot not targeted
|
2018-08-03 21:31:45 +02:00
|
|
|
if ($mode eq "+b") {
|
|
|
|
if ($nick eq "ChanServ" or $target =~ m/##fix_your_connection$/i) {
|
2015-06-26 05:55:42 +02:00
|
|
|
if ($self->{pbot}->{chanops}->can_gain_ops($channel)) {
|
2014-08-11 09:34:30 +02:00
|
|
|
$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;
|
|
|
|
}
|
2017-05-21 11:20:44 +02:00
|
|
|
} elsif ($target =~ m/^\*!\*@/ or $target =~ m/^\*!.*\@gateway\/web/i) {
|
|
|
|
my $timeout = 60 * 60 * 24 * 7;
|
|
|
|
|
|
|
|
if ($target =~ m/\// and $target !~ m/\@gateway/) {
|
|
|
|
$timeout = 0; # permanent bans for cloaks that aren't gateway
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($timeout && $self->{pbot}->{chanops}->can_gain_ops($channel)) {
|
2017-05-24 02:05:25 +02:00
|
|
|
if (not exists $self->{pbot}->{chanops}->{unban_timeout}->hash->{lc $channel}->{lc $target}) {
|
|
|
|
$self->{pbot}->{logger}->log("Temp ban for $target in $channel.\n");
|
|
|
|
$self->{pbot}->{chanops}->{unban_timeout}->hash->{$channel}->{$target}{timeout} = gettimeofday + $timeout;
|
|
|
|
$self->{pbot}->{chanops}->{unban_timeout}->save;
|
|
|
|
}
|
2017-05-21 11:20:44 +02:00
|
|
|
}
|
2011-02-13 10:05:48 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-03 21:31:45 +02:00
|
|
|
elsif ($mode eq "+q") {
|
|
|
|
if ($nick ne $event->{conn}->nick) { # bot muted
|
2015-06-26 05:55:42 +02:00
|
|
|
if ($self->{pbot}->{chanops}->can_gain_ops($channel)) {
|
2015-05-27 19:46:30 +02:00
|
|
|
$self->{pbot}->{chanops}->{unmute_timeout}->hash->{$channel}->{$target}{timeout} = gettimeofday + $self->{pbot}->{registry}->get_value('bantracker', 'mute_timeout');
|
|
|
|
$self->{pbot}->{chanops}->{unmute_timeout}->save;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub on_join {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my ($nick, $user, $host, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to);
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2017-06-18 12:40:51 +02:00
|
|
|
($nick, $user, $host) = $self->normalize_hostmask($nick, $user, $host);
|
|
|
|
|
2016-11-29 10:44:31 +01:00
|
|
|
$channel = lc $channel;
|
|
|
|
|
2014-05-13 12:15:52 +02:00
|
|
|
my $message_account = $self->{pbot}->{messagehistory}->get_message_account($nick, $user, $host);
|
|
|
|
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, "JOIN", $self->{pbot}->{messagehistory}->{MSG_JOIN});
|
2016-08-28 12:49:27 +02:00
|
|
|
|
2016-11-29 10:44:31 +01:00
|
|
|
$self->{pbot}->{messagehistory}->{database}->devalidate_channel($message_account, $channel);
|
|
|
|
|
2016-08-28 12:49:27 +02:00
|
|
|
my $msg = 'JOIN';
|
|
|
|
|
|
|
|
if (exists $self->{pbot}->{capabilities}->{'extended-join'}) {
|
|
|
|
$msg .= " $event->{event}->{args}[0] :$event->{event}->{args}[1]";
|
|
|
|
|
|
|
|
$self->{pbot}->{messagehistory}->{database}->update_gecos($message_account, $event->{event}->{args}[1], scalar gettimeofday);
|
|
|
|
|
|
|
|
if ($event->{event}->{args}[0] ne '*') {
|
|
|
|
$self->{pbot}->{messagehistory}->{database}->link_aliases($message_account, undef, $event->{event}->{args}[0]);
|
|
|
|
$self->{pbot}->{antiflood}->check_nickserv_accounts($nick, $event->{event}->{args}[0]);
|
2016-11-29 10:44:31 +01:00
|
|
|
} else {
|
|
|
|
$self->{pbot}->{messagehistory}->{database}->set_current_nickserv_account($message_account, '');
|
2016-08-28 12:49:27 +02:00
|
|
|
}
|
2016-08-30 11:14:21 +02:00
|
|
|
|
|
|
|
$self->{pbot}->{antiflood}->check_bans($message_account, $event->{event}->from, $channel);
|
2016-08-28 12:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$self->{pbot}->{antiflood}->check_flood($channel, $nick, $user, $host, $msg,
|
2014-05-19 04:42:18 +02:00
|
|
|
$self->{pbot}->{registry}->get_value('antiflood', 'join_flood_threshold'),
|
|
|
|
$self->{pbot}->{registry}->get_value('antiflood', 'join_flood_time_threshold'),
|
|
|
|
$self->{pbot}->{messagehistory}->{MSG_JOIN});
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
2016-07-01 22:01:34 +02:00
|
|
|
sub on_invite {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my ($nick, $user, $host, $target, $channel) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to, $event->{event}->{args}[0]);
|
|
|
|
|
2017-06-18 12:40:51 +02:00
|
|
|
($nick, $user, $host) = $self->normalize_hostmask($nick, $user, $host);
|
|
|
|
|
2016-11-29 10:44:31 +01:00
|
|
|
$channel = lc $channel;
|
|
|
|
|
2016-07-01 22:01:34 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick!$user\@$host invited $target to $channel!\n");
|
|
|
|
|
|
|
|
if ($target eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) {
|
|
|
|
if ($self->{pbot}->{channels}->is_active($channel)) {
|
|
|
|
$self->{pbot}->{interpreter}->add_botcmd_to_command_queue($channel, "join $channel", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-15 17:49:56 +02:00
|
|
|
sub on_kick {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my ($nick, $user, $host, $target, $channel, $reason) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to, $event->{event}->{args}[0], $event->{event}->{args}[1]);
|
2016-11-29 10:44:31 +01:00
|
|
|
$channel = lc $channel;
|
2014-05-15 17:49:56 +02:00
|
|
|
|
2017-06-18 12:40:51 +02:00
|
|
|
($nick, $user, $host) = $self->normalize_hostmask($nick, $user, $host);
|
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick!$user\@$host kicked $target from $channel ($reason)\n");
|
2014-05-15 17:49:56 +02:00
|
|
|
|
|
|
|
my ($message_account) = $self->{pbot}->{messagehistory}->{database}->find_message_account_by_nick($target);
|
|
|
|
|
2014-10-14 04:32:22 +02:00
|
|
|
my $hostmask;
|
2018-08-03 21:31:45 +02:00
|
|
|
if (defined $message_account) {
|
2014-10-14 04:32:22 +02:00
|
|
|
$hostmask = $self->{pbot}->{messagehistory}->{database}->find_most_recent_hostmask($message_account);
|
2014-05-15 17:49:56 +02:00
|
|
|
|
|
|
|
my ($target_nick, $target_user, $target_host) = $hostmask =~ m/^([^!]+)!([^@]+)@(.*)/;
|
|
|
|
my $text = "KICKED by $nick!$user\@$host ($reason)";
|
|
|
|
|
2014-10-14 04:32:22 +02:00
|
|
|
$self->{pbot}->{messagehistory}->add_message($message_account, $hostmask, $channel, $text, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE});
|
2014-05-19 04:42:18 +02:00
|
|
|
$self->{pbot}->{antiflood}->check_flood($channel, $target_nick, $target_user, $target_host, $text,
|
|
|
|
$self->{pbot}->{registry}->get_value('antiflood', 'join_flood_threshold'),
|
|
|
|
$self->{pbot}->{registry}->get_value('antiflood', 'join_flood_time_threshold'),
|
|
|
|
$self->{pbot}->{messagehistory}->{MSG_DEPARTURE});
|
2014-05-15 17:49:56 +02:00
|
|
|
}
|
2014-10-14 04:32:22 +02:00
|
|
|
|
|
|
|
$message_account = $self->{pbot}->{messagehistory}->{database}->get_message_account_id("$nick!$user\@$host");
|
|
|
|
|
2018-08-03 21:31:45 +02:00
|
|
|
if (defined $message_account) {
|
2014-10-14 04:32:22 +02:00
|
|
|
my $text = "KICKED " . (defined $hostmask ? $hostmask : $target) . " from $channel ($reason)";
|
|
|
|
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, $text, $self->{pbot}->{messagehistory}->{MSG_CHAT});
|
|
|
|
}
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
2014-05-15 17:49:56 +02:00
|
|
|
}
|
|
|
|
|
2010-03-17 07:36:54 +01:00
|
|
|
sub on_departure {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my ($nick, $user, $host, $channel, $args) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to, $event->{event}->args);
|
2016-11-29 10:44:31 +01:00
|
|
|
$channel = lc $channel;
|
2010-06-10 22:26:09 +02:00
|
|
|
|
2017-06-18 12:40:51 +02:00
|
|
|
($nick, $user, $host) = $self->normalize_hostmask($nick, $user, $host);
|
|
|
|
|
2014-11-01 01:15:21 +01:00
|
|
|
my $text = uc $event->{event}->type;
|
2010-06-10 22:26:09 +02:00
|
|
|
$text .= " $args";
|
|
|
|
|
2014-05-13 12:15:52 +02:00
|
|
|
my $message_account = $self->{pbot}->{messagehistory}->get_message_account($nick, $user, $host);
|
|
|
|
|
2018-08-03 21:31:45 +02:00
|
|
|
if ($text =~ m/^QUIT/) {
|
2014-05-13 12:15:52 +02:00
|
|
|
# QUIT messages must be dispatched to each channel the user is on
|
2015-02-14 13:03:39 +01:00
|
|
|
my $channels = $self->{pbot}->{nicklist}->get_channels($nick);
|
|
|
|
foreach my $chan (@$channels) {
|
2014-05-16 02:48:46 +02:00
|
|
|
next if $chan !~ m/^#/;
|
2014-05-15 03:39:33 +02:00
|
|
|
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $chan, $text, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE});
|
2014-05-13 12:15:52 +02:00
|
|
|
}
|
|
|
|
} else {
|
2014-05-15 03:39:33 +02:00
|
|
|
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, $text, $self->{pbot}->{messagehistory}->{MSG_DEPARTURE});
|
2014-05-13 12:15:52 +02:00
|
|
|
}
|
|
|
|
|
2014-05-19 04:42:18 +02:00
|
|
|
$self->{pbot}->{antiflood}->check_flood($channel, $nick, $user, $host, $text,
|
|
|
|
$self->{pbot}->{registry}->get_value('antiflood', 'join_flood_threshold'),
|
|
|
|
$self->{pbot}->{registry}->get_value('antiflood', 'join_flood_time_threshold'),
|
|
|
|
$self->{pbot}->{messagehistory}->{MSG_DEPARTURE});
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
my $admin = $self->{pbot}->{admins}->find_admin($channel, "$nick!$user\@$host");
|
2018-08-03 21:31:45 +02:00
|
|
|
if (defined $admin and $admin->{loggedin} and not $admin->{stayloggedin}) {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("Whoops, $nick left while still logged in.\n");
|
|
|
|
$self->{pbot}->{logger}->log("Logged out $nick.\n");
|
2012-10-27 23:03:10 +02:00
|
|
|
delete $admin->{loggedin};
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
2014-05-31 03:07:29 +02:00
|
|
|
}
|
|
|
|
|
2017-05-21 11:20:44 +02:00
|
|
|
sub on_map {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
|
|
|
|
# remove and discard first and last elements
|
|
|
|
shift @{ $event->{event}->{args} };
|
|
|
|
pop @{ $event->{event}->{args} };
|
|
|
|
|
|
|
|
foreach my $arg (@{ $event->{event}->{args} }) {
|
|
|
|
my ($key, $value) = split /=/, $arg;
|
|
|
|
$self->{pbot}->{ircd}->{$key} = $value;
|
|
|
|
$self->{pbot}->{logger}->log(" $key\n") if not defined $value;
|
|
|
|
$self->{pbot}->{logger}->log(" $key=$value\n") if defined $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-28 12:49:27 +02:00
|
|
|
sub on_cap {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
|
|
|
|
if ($event->{event}->{args}->[0] eq 'ACK') {
|
|
|
|
$self->{pbot}->{logger}->log("Client capabilities granted: " . $event->{event}->{args}->[1] . "\n");
|
|
|
|
|
2017-09-02 09:39:29 +02:00
|
|
|
my @caps = split /\s+/, $event->{event}->{args}->[1];
|
2016-08-28 12:49:27 +02:00
|
|
|
foreach my $cap (@caps) {
|
|
|
|
$self->{pbot}->{capabilities}->{$cap} = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$self->{pbot}->{logger}->log(Dumper $event->{event});
|
|
|
|
}
|
2016-11-29 10:44:31 +01:00
|
|
|
return 0;
|
2016-08-28 12:49:27 +02:00
|
|
|
}
|
|
|
|
|
2014-05-16 02:48:46 +02:00
|
|
|
sub on_nickchange {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my ($nick, $user, $host, $newnick) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args);
|
2014-05-16 02:48:46 +02:00
|
|
|
|
2017-06-18 12:40:51 +02:00
|
|
|
($nick, $user, $host) = $self->normalize_hostmask($nick, $user, $host);
|
|
|
|
|
2016-11-29 10:44:31 +01:00
|
|
|
$self->{pbot}->{logger}->log("[NICKCHANGE] $nick!$user\@$host changed nick to $newnick\n");
|
2014-05-16 02:48:46 +02:00
|
|
|
|
2015-05-13 07:51:04 +02:00
|
|
|
if ($newnick eq $self->{pbot}->{registry}->get_value('irc', 'botnick') and not $self->{pbot}->{joined_channels}) {
|
2015-07-29 02:47:53 +02:00
|
|
|
my $chans;
|
2015-05-13 07:51:04 +02:00
|
|
|
foreach my $chan (keys %{ $self->{pbot}->{channels}->{channels}->hash }) {
|
2018-08-03 21:31:45 +02:00
|
|
|
if ($self->{pbot}->{channels}->{channels}->hash->{$chan}{enabled}) {
|
2015-07-29 02:47:53 +02:00
|
|
|
$chans .= "$chan,";
|
2015-05-13 07:51:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-29 02:47:53 +02:00
|
|
|
$self->{pbot}->{logger}->log("Joining channels: $chans\n");
|
|
|
|
$self->{pbot}->{chanops}->join_channel($chans);
|
2015-05-13 07:51:04 +02:00
|
|
|
$self->{pbot}->{joined_channels} = 1;
|
2016-11-29 10:44:31 +01:00
|
|
|
return 0;
|
2015-05-13 07:51:04 +02:00
|
|
|
}
|
|
|
|
|
2014-05-16 02:48:46 +02:00
|
|
|
my $message_account = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
2014-08-12 07:51:21 +02:00
|
|
|
$self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($message_account, $self->{pbot}->{antiflood}->{NEEDS_CHECKBAN});
|
2016-12-01 13:57:25 +01:00
|
|
|
my $channels = $self->{pbot}->{nicklist}->get_channels($nick);
|
2015-02-14 13:03:39 +01:00
|
|
|
foreach my $channel (@$channels) {
|
2014-05-16 02:48:46 +02:00
|
|
|
next if $channel !~ m/^#/;
|
|
|
|
$self->{pbot}->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $channel, "NICKCHANGE $newnick", $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE});
|
|
|
|
}
|
2016-12-01 13:57:25 +01:00
|
|
|
$self->{pbot}->{messagehistory}->{database}->update_hostmask_data("$nick!$user\@$host", { last_seen => scalar gettimeofday });
|
2014-05-16 02:48:46 +02:00
|
|
|
|
2015-05-22 13:24:38 +02:00
|
|
|
my $newnick_account = $self->{pbot}->{messagehistory}->{database}->get_message_account($newnick, $user, $host, $nick);
|
2014-08-12 07:51:21 +02:00
|
|
|
$self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($newnick_account, $self->{pbot}->{antiflood}->{NEEDS_CHECKBAN});
|
2016-08-18 05:34:45 +02:00
|
|
|
$self->{pbot}->{messagehistory}->{database}->update_hostmask_data("$newnick!$user\@$host", { last_seen => scalar gettimeofday });
|
2014-05-16 02:48:46 +02:00
|
|
|
|
2014-05-19 04:42:18 +02:00
|
|
|
$self->{pbot}->{antiflood}->check_flood("$nick!$user\@$host", $nick, $user, $host, "NICKCHANGE $newnick",
|
|
|
|
$self->{pbot}->{registry}->get_value('antiflood', 'nick_flood_threshold'),
|
|
|
|
$self->{pbot}->{registry}->get_value('antiflood', 'nick_flood_time_threshold'),
|
|
|
|
$self->{pbot}->{messagehistory}->{MSG_NICKCHANGE});
|
2015-05-22 13:24:38 +02:00
|
|
|
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-11 00:56:43 +01:00
|
|
|
sub on_nicknameinuse {
|
2014-11-01 01:15:21 +01:00
|
|
|
my ($self, $event_type, $event) = @_;
|
2018-08-06 07:47:38 +02:00
|
|
|
my (undef, $nick, $msg) = $event->{event}->args;
|
2015-01-11 00:56:43 +01:00
|
|
|
my $from = $event->{event}->from;
|
2014-11-01 01:15:21 +01:00
|
|
|
|
2015-01-11 00:56:43 +01:00
|
|
|
$self->{pbot}->{logger}->log("Received nicknameinuse for nick $nick from $from: $msg\n");
|
|
|
|
$event->{conn}->privmsg("nickserv", "ghost $nick " . $self->{pbot}->{registry}->get_value('irc', 'identify_password'));
|
2014-11-01 01:15:21 +01:00
|
|
|
return 0;
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
|
|
|
|
2018-08-06 07:47:38 +02:00
|
|
|
sub on_channelmodeis {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my (undef, $channel, $modes) = $event->{event}->args;
|
|
|
|
$self->{pbot}->{channels}->{channels}->set($channel, 'MODE', $modes, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_topic {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
|
|
|
|
if (not length $event->{event}->{to}->[0]) {
|
|
|
|
# on join
|
|
|
|
my (undef, $channel, $topic) = $event->{event}->args;
|
|
|
|
$self->{pbot}->{logger}->log("Topic for $channel: $topic\n");
|
|
|
|
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC', $topic, 1);
|
|
|
|
} else {
|
|
|
|
# user changing topic
|
|
|
|
my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host);
|
|
|
|
my $channel = $event->{event}->{to}->[0];
|
|
|
|
my $topic = $event->{event}->{args}->[0];
|
|
|
|
|
|
|
|
$self->{pbot}->{logger}->log("$nick!$user\@$host changed topic for $channel to: $topic\n");
|
|
|
|
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC', $topic, 1);
|
|
|
|
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC_SET_BY', "$nick!$user\@$host", 1);
|
|
|
|
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC_SET_ON', gettimeofday);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_topicinfo {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
my (undef, $channel, $by, $timestamp) = $event->{event}->args;
|
|
|
|
$self->{pbot}->{logger}->log("Topic for $channel set by $by on $timestamp\n");
|
|
|
|
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC_SET_BY', $by, 1);
|
|
|
|
$self->{pbot}->{channels}->{channels}->set($channel, 'TOPIC_SET_ON', $timestamp, 1);
|
|
|
|
}
|
|
|
|
|
2017-06-18 12:40:51 +02:00
|
|
|
sub normalize_hostmask {
|
|
|
|
my ($self, $nick, $user, $host) = @_;
|
|
|
|
|
|
|
|
if ($host =~ m{^(gateway|nat)/(.*)/x-[^/]+$}) {
|
|
|
|
$host = "$1/$2/x-$user";
|
|
|
|
}
|
|
|
|
|
2017-06-20 03:21:47 +02:00
|
|
|
$host =~ s{/session$}{/x-$user};
|
|
|
|
|
2017-06-18 12:40:51 +02:00
|
|
|
return ($nick, $user, $host);
|
|
|
|
}
|
|
|
|
|
2017-08-02 06:35:56 +02:00
|
|
|
my %who_queue;
|
|
|
|
my %who_cache;
|
|
|
|
my $last_who_id;
|
|
|
|
my $who_pending = 0;
|
|
|
|
|
|
|
|
sub on_whospcrpl {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
|
|
|
|
my ($ignored, $id, $user, $host, $nick, $nickserv, $gecos) = @{$event->{event}->{args}};
|
|
|
|
($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host);
|
|
|
|
$last_who_id = $id;
|
|
|
|
my $hostmask = "$nick!$user\@$host";
|
|
|
|
my $channel = $who_cache{$id};
|
|
|
|
delete $who_queue{$id};
|
|
|
|
|
|
|
|
return 0 if not defined $channel;
|
|
|
|
|
|
|
|
$self->{pbot}->{logger}->log("WHO id: $id, hostmask: $hostmask, $nickserv, $gecos.\n");
|
|
|
|
|
|
|
|
my $account_id = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
|
|
|
$self->{pbot}->{messagehistory}->{database}->update_hostmask_data($hostmask, { last_seen => scalar gettimeofday });
|
|
|
|
|
|
|
|
if ($nickserv ne '0') {
|
|
|
|
$self->{pbot}->{messagehistory}->{database}->link_aliases($account_id, undef, $nickserv);
|
|
|
|
$self->{pbot}->{antiflood}->check_nickserv_accounts($nick, $nickserv);
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->{pbot}->{messagehistory}->{database}->link_aliases($account_id, $hostmask, undef);
|
|
|
|
|
|
|
|
$self->{pbot}->{messagehistory}->{database}->devalidate_channel($account_id, $channel);
|
|
|
|
$self->{pbot}->{antiflood}->check_bans($account_id, $hostmask, $channel);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_endofwho {
|
|
|
|
my ($self, $event_type, $event) = @_;
|
|
|
|
$self->{pbot}->{logger}->log("WHO session $last_who_id ($who_cache{$last_who_id}) completed.\n");
|
|
|
|
delete $who_cache{$last_who_id};
|
2018-08-03 22:38:28 +02:00
|
|
|
delete $who_queue{$last_who_id};
|
2017-08-02 06:35:56 +02:00
|
|
|
$who_pending = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub send_who {
|
|
|
|
my ($self, $channel) = @_;
|
|
|
|
$self->{pbot}->{logger}->log("pending WHO to $channel\n");
|
|
|
|
|
|
|
|
for (my $id = 1; $id < 99; $id++) {
|
|
|
|
if (not exists $who_cache{$id}) {
|
|
|
|
$who_cache{$id} = $channel;
|
|
|
|
$who_queue{$id} = $channel;
|
|
|
|
$last_who_id = $id;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub check_pending_whos {
|
|
|
|
my $self = shift;
|
|
|
|
return if $who_pending;
|
|
|
|
foreach my $id (keys %who_queue) {
|
|
|
|
$self->{pbot}->{logger}->log("sending WHO to $who_queue{$id} [$id]\n");
|
|
|
|
$self->{pbot}->{conn}->sl("WHO $who_queue{$id} %tuhnar,$id");
|
|
|
|
$who_pending = 1;
|
2018-08-03 22:38:28 +02:00
|
|
|
$last_who_id = $id;
|
2017-08-02 06:35:56 +02:00
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-17 07:36:54 +01:00
|
|
|
1;
|