3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-10 05:59:32 +01:00
pbot/lib/PBot/Core/Handlers/Users.pm

91 lines
3.0 KiB
Perl
Raw Normal View History

2021-07-21 21:43:30 +02:00
# File: Users.pm
#
# Purpose: Handles IRC events related to PBot user accounts and user metadata.
2023-02-21 06:31:52 +01:00
# SPDX-FileCopyrightText: 2010-2023 Pragmatic Software <pragma78@gmail.com>
2021-07-21 21:43:30 +02:00
# SPDX-License-Identifier: MIT
2021-07-24 01:57:33 +02:00
package PBot::Core::Handlers::Users;
2021-07-21 21:43:30 +02:00
use PBot::Imports;
use parent 'PBot::Core::Class';
2021-07-21 21:43:30 +02:00
sub initialize {
my ($self, %conf) = @_;
$self->{pbot}->{event_dispatcher}->register_handler('irc.join', sub { $self->on_join (@_) });
$self->{pbot}->{event_dispatcher}->register_handler('irc.part', sub { $self->on_departure (@_) });
$self->{pbot}->{event_dispatcher}->register_handler('irc.quit', sub { $self->on_departure (@_) });
$self->{pbot}->{event_dispatcher}->register_handler('irc.kick', sub { $self->on_kick (@_) });
$self->{pbot}->{event_dispatcher}->register_handler('pbot.part', sub { $self->on_self_part (@_) });
}
sub on_join {
my ($self, $event_type, $event) = @_;
my ($nick, $user, $host, $channel) = (
2023-01-31 14:44:34 +01:00
$event->nick,
$event->user,
$event->host,
$event->to
2021-07-21 21:43:30 +02:00
);
($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host);
my ($u, $name) = $self->{pbot}->{users}->find_user($channel, "$nick!$user\@$host");
if (defined $u) {
if ($self->{pbot}->{chanops}->can_gain_ops($channel)) {
my $modes = '+';
my $targets = '';
if ($u->{autoop}) {
$self->{pbot}->{logger}->log("$nick!$user\@$host autoop in $channel\n");
$modes .= 'o';
$targets .= "$nick ";
}
if ($u->{autovoice}) {
$self->{pbot}->{logger}->log("$nick!$user\@$host autovoice in $channel\n");
$modes .= 'v';
$targets .= "$nick ";
}
if (length $modes > 1) {
$self->{pbot}->{chanops}->add_op_command($channel, "mode $channel $modes $targets");
$self->{pbot}->{chanops}->gain_ops($channel);
}
}
if ($u->{autologin}) {
$self->{pbot}->{logger}->log("$nick!$user\@$host autologin to $name for $channel\n");
$u->{loggedin} = 1;
}
}
return 1;
2021-07-21 21:43:30 +02:00
}
sub on_departure {
my ($self, $event_type, $event) = @_;
2023-01-31 14:44:34 +01:00
my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->to);
2021-07-21 21:43:30 +02:00
($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host);
$self->{pbot}->{users}->decache_user($channel, "$nick!$user\@$host");
return 1;
2021-07-21 21:43:30 +02:00
}
sub on_kick {
my ($self, $event_type, $event) = @_;
2023-01-31 14:44:34 +01:00
my ($nick, $user, $host, $channel) = ($event->nick, $event->user, $event->host, $event->{args}[0]);
2021-07-21 21:43:30 +02:00
($nick, $user, $host) = $self->{pbot}->{irchandlers}->normalize_hostmask($nick, $user, $host);
$self->{pbot}->{users}->decache_user($channel, "$nick!$user\@$host");
return 1;
2021-07-21 21:43:30 +02:00
}
sub on_self_part {
my ($self, $event_type, $event) = @_;
delete $self->{pbot}->{users}->{user_cache}->{lc $event->{channel}};
return 1;
2021-07-21 21:43:30 +02:00
}
1;