mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-23 10:34:52 +01:00
RegisterNickserv: Queue unregistered messages to see if speaker gets killed or leaves
This commit is contained in:
parent
7e47d513b4
commit
42f967e411
@ -6,6 +6,8 @@ use strict;
|
|||||||
|
|
||||||
use Carp ();
|
use Carp ();
|
||||||
|
|
||||||
|
use Time::HiRes qw/gettimeofday/;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
|
Carp::croak("Options to " . __FILE__ . " should be key/value pairs, not hash reference") if ref $_[1] eq 'HASH';
|
||||||
my ($class, %conf) = @_;
|
my ($class, %conf) = @_;
|
||||||
@ -18,10 +20,13 @@ sub initialize {
|
|||||||
my ($self, %conf) = @_;
|
my ($self, %conf) = @_;
|
||||||
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
|
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference to " . __FILE__);
|
||||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
|
$self->{pbot}->{event_dispatcher}->register_handler('irc.public', sub { $self->on_public(@_) });
|
||||||
|
$self->{queue} = [];
|
||||||
|
$self->{pbot}->{timer}->register(sub { $self->check_queue }, 1, 'RegisterNickserv');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub unload {
|
sub unload {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
$self->{pbot}->{timer}->unregister('RegisterNickserv');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub on_public {
|
sub on_public {
|
||||||
@ -29,22 +34,17 @@ sub on_public {
|
|||||||
my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args);
|
my ($nick, $user, $host, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args);
|
||||||
my $channel = lc $event->{event}->{to}[0];
|
my $channel = lc $event->{event}->{to}[0];
|
||||||
|
|
||||||
if ($self->{pbot}->{ignorelist}->check_ignore($nick, $user, $host, $channel, 1)) {
|
|
||||||
my $admin = $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host");
|
|
||||||
if (!defined $admin || $admin->{level} < 10) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# exit if channel hasn't muted $~a
|
# exit if channel hasn't muted $~a
|
||||||
return 0 if not exists $self->{pbot}->{bantracker}->{banlist}->{$channel}->{'+q'}->{'$~a'};
|
return 0 if not exists $self->{pbot}->{bantracker}->{banlist}->{$channel}->{'+q'}->{'$~a'};
|
||||||
|
|
||||||
my $account = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
my $account = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
||||||
my $nickserv = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($account);
|
my $nickserv = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($account);
|
||||||
|
|
||||||
my $nickserv_text = $nickserv ? "is logged into $nickserv" : "is not logged in";
|
# debug
|
||||||
$self->{pbot}->{logger}->log("RegisterNickserv: $nick!$user\@$host ($account) $nickserv_text.\n");
|
# my $nickserv_text = $nickserv ? "is logged into $nickserv" : "is not logged in";
|
||||||
|
# $self->{pbot}->{logger}->log("RegisterNickserv: $nick!$user\@$host ($account) $nickserv_text.\n");
|
||||||
|
|
||||||
|
# exit if user is identified
|
||||||
return 0 if defined $nickserv && length $nickserv;
|
return 0 if defined $nickserv && length $nickserv;
|
||||||
|
|
||||||
my @filters = (
|
my @filters = (
|
||||||
@ -70,10 +70,28 @@ sub on_public {
|
|||||||
# don't relay unregistered chat unless enabled
|
# don't relay unregistered chat unless enabled
|
||||||
return 0 if not $self->{pbot}->{registry}->get_value($channel, 'relay_unregistered_chat');
|
return 0 if not $self->{pbot}->{registry}->get_value($channel, 'relay_unregistered_chat');
|
||||||
|
|
||||||
$self->{pbot}->{logger}->log("RegisterNickserv: Relaying unregistered message to $channel: <$nick> $msg\n");
|
# add message to delay send queue to see if Sigyn kills them first (or if they leave)
|
||||||
$event->{conn}->privmsg($channel, "(unregistered) <$nick> $msg");
|
$self->{pbot}->{logger}->log("RegisterNickserv: Queuing unregistered message for $channel: <$nick> $msg\n");
|
||||||
|
push @{$self->{queue}}, [gettimeofday + 10, $channel, $nick, $msg];
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub check_queue {
|
||||||
|
my $self = shift;
|
||||||
|
my $now = gettimeofday;
|
||||||
|
|
||||||
|
return if not @{$self->{queue}};
|
||||||
|
|
||||||
|
my ($time, $channel, $nick, $msg) = @{$self->{queue}->[0]};
|
||||||
|
|
||||||
|
if ($now >= $time) {
|
||||||
|
# if nick is still present in channel, send the message
|
||||||
|
if ($self->{pbot}->{nicklist}->is_present($channel, $nick)) {
|
||||||
|
$self->{pbot}->{conn}->privmsg($channel, "(unregistered) <$nick> $msg");
|
||||||
|
}
|
||||||
|
shift @{$self->{queue}};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user