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
|
|
|
|
|
|
|
|
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;
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2010-03-22 08:33:44 +01:00
|
|
|
sub new {
|
|
|
|
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(@_) });
|
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) = @_;
|
|
|
|
|
2014-11-01 01:15:21 +01:00
|
|
|
if(not defined $self->{pbot}->{event_dispatcher}->dispatch_event("irc.$event->{type}", { conn => $conn, event => $event })) {
|
|
|
|
if ($self->{pbot}->{registry}->get_value('irc', 'log_default_handler')) {
|
|
|
|
my $dump = Dumper $event;
|
|
|
|
$self->{pbot}->{logger}->log($dump);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$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];
|
2014-05-17 22:08:19 +02:00
|
|
|
my $bot_trigger = $self->{pbot}->{registry}->get_value('general', 'trigger');
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2014-05-17 22:08:19 +02:00
|
|
|
$text =~ s/^\Q$bot_trigger\E?(.*)/$bot_trigger$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) = @_;
|
|
|
|
my ($nick, $host) = ($event->{event}->nick, $event->{event}->host);
|
|
|
|
my $text = $event->{event}->{args}[0];
|
2010-03-17 07:36:54 +01:00
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("Received NOTICE from $nick $host '$text'\n");
|
2015-01-11 00:56:43 +01:00
|
|
|
|
|
|
|
if($nick eq 'NickServ') {
|
|
|
|
if($text =~ m/This nickname is registered/) {
|
|
|
|
$self->{pbot}->{logger}->log("Identifying with NickServ . . .\n");
|
|
|
|
$event->{conn}->privmsg("nickserv", "identify " . $self->{pbot}->{registry}->get_value('irc', 'identify_password'));
|
|
|
|
} elsif($text =~ m/You are now identified/) {
|
|
|
|
$event->{conn}->nick($self->{pbot}->{registry}->get_value('irc', 'botnick'));
|
|
|
|
foreach my $chan (keys %{ $self->{pbot}->{channels}->{channels}->hash }) {
|
|
|
|
if($self->{pbot}->{channels}->{channels}->hash->{$chan}{enabled}) {
|
|
|
|
$self->{pbot}->{logger}->log("Joining channel: $chan\n");
|
|
|
|
$self->{pbot}->{chanops}->join_channel($chan);
|
|
|
|
}
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
2015-01-11 00:56:43 +01:00
|
|
|
$self->{pbot}->{joined_channels} = 1;
|
|
|
|
} elsif($text =~ m/has been ghosted/) {
|
|
|
|
$event->{conn}->nick($self->{pbot}->{registry}->get_value('irc', 'botnick'));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-02-13 10:05:48 +01:00
|
|
|
my ($mode, $modifier);
|
|
|
|
my $i = 0;
|
|
|
|
my $target;
|
2011-02-13 06:07:02 +01:00
|
|
|
|
2011-02-13 10:05:48 +01:00
|
|
|
while($mode_string =~ m/(.)/g) {
|
|
|
|
my $char = $1;
|
2011-02-13 06:07:02 +01:00
|
|
|
|
2011-02-13 10:05:48 +01:00
|
|
|
if($char eq '-' or $char eq '+') {
|
|
|
|
$modifier = $char;
|
|
|
|
next;
|
|
|
|
}
|
2011-02-13 06:07:02 +01:00
|
|
|
|
2011-02-13 10:05:48 +01:00
|
|
|
$mode = $modifier . $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
|
|
|
|
2011-02-13 10:05:48 +01: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
|
|
|
|
2014-05-17 22:08:19 +02:00
|
|
|
if(defined $target && $target eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) { # bot targeted
|
2011-02-13 10:05:48 +01:00
|
|
|
if($mode eq "+o") {
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick opped me in $channel\n");
|
2014-05-23 07:03:54 +02:00
|
|
|
$self->{pbot}->{chanops}->{is_opped}->{$channel}{timeout} = gettimeofday + $self->{pbot}->{registry}->get_value('general', 'deop_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
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2011-02-13 10:05:48 +01: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
|
|
|
|
if($mode eq "+b") {
|
|
|
|
if($nick eq "ChanServ") {
|
2014-08-11 09:34:30 +02:00
|
|
|
if (exists $self->{pbot}->{channels}->{channels}->hash->{$channel} and $self->{pbot}->{channels}->{channels}->hash->{$channel}{chanop}) {
|
|
|
|
$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;
|
|
|
|
}
|
2011-02-13 10:05:48 +01:00
|
|
|
}
|
|
|
|
}
|
2014-05-17 22:08:19 +02:00
|
|
|
elsif($mode eq "+e" && $channel eq $self->{pbot}->{registry}->get_value('irc', 'botnick')) {
|
2014-05-18 22:09:05 +02:00
|
|
|
foreach my $chan (keys %{ $self->{pbot}->{channels}->{channels}->hash }) {
|
|
|
|
if($self->{channels}->{channels}->hash->{$chan}{enabled}) {
|
|
|
|
$self->{pbot}->{logger}->log("Joining channel: $chan\n");
|
2014-11-01 01:15:21 +01:00
|
|
|
$event->{conn}->join($chan);
|
2011-02-13 10:05:48 +01:00
|
|
|
}
|
2010-03-17 07:36:54 +01:00
|
|
|
}
|
2011-02-13 10:05:48 +01:00
|
|
|
$self->{pbot}->{joined_channels} = 1;
|
|
|
|
}
|
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
|
|
|
|
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});
|
2014-05-19 04:42:18 +02:00
|
|
|
$self->{pbot}->{antiflood}->check_flood($channel, $nick, $user, $host, "JOIN",
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
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]);
|
2014-05-15 17:49:56 +02:00
|
|
|
|
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;
|
2014-05-15 17:49:56 +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");
|
|
|
|
|
|
|
|
if(defined $message_account) {
|
|
|
|
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);
|
2010-06-10 22:26:09 +02:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
if($text =~ m/^QUIT/) {
|
|
|
|
# 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");
|
2012-10-27 23:03:10 +02:00
|
|
|
if(defined $admin and $admin->{loggedin}) {
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-05-18 22:09:05 +02:00
|
|
|
$self->{pbot}->{logger}->log("$nick!$user\@$host changed nick to $newnick\n");
|
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});
|
2015-02-14 13:03:39 +01:00
|
|
|
my $channels = $self->{pbot}->{nicklist}->get_channels($nick);
|
|
|
|
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});
|
|
|
|
}
|
|
|
|
|
|
|
|
my $newnick_account = $self->{pbot}->{messagehistory}->{database}->get_message_account($newnick, $user, $host);
|
2014-08-12 07:51:21 +02:00
|
|
|
$self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($newnick_account, $self->{pbot}->{antiflood}->{NEEDS_CHECKBAN});
|
2014-05-16 02:48:46 +02:00
|
|
|
$self->{pbot}->{messagehistory}->{database}->update_hostmask_data($newnick_account, { last_seen => scalar gettimeofday });
|
|
|
|
|
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});
|
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) = @_;
|
2015-01-11 00:56:43 +01:00
|
|
|
my ($unused, $nick, $msg) = $event->{event}->args;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
1;
|