3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 01:48:38 +02:00

StdinReader: add general.daemon registry item; give stdin bot account botowner capability

This commit is contained in:
Pragmatic Software 2020-02-03 19:25:21 -08:00
parent 58233293fb
commit 437da18ac7

View File

@ -25,19 +25,23 @@ sub initialize {
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference in StdinReader");
# create implicit bot-admin account for bot
if (not $self->{pbot}->{users}->find_admin('.*', '*!stdin@pbot')) {
my $user = $self->{pbot}->{users}->find_user('.*', '*!stdin@pbot');
if (not defined $user or not $self->{pbot}->{capabilities}->userhas($user, 'botowner')) {
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
$self->{pbot}->{logger}->log("Adding stdin admin *!stdin\@pbot...\n");
$self->{pbot}->{users}->add_user($botnick, '.*', '*!stdin@pbot', 100, undef, 1);
$self->{pbot}->{logger}->log("Adding stdin botowner *!stdin\@pbot...\n");
$self->{pbot}->{users}->add_user($botnick, '.*', '*!stdin@pbot', 'botowner', undef, 1);
$self->{pbot}->{users}->login($botnick, "$botnick!stdin\@pbot", undef);
$self->{pbot}->{users}->save;
}
# used to check whether process is in background or foreground, for stdin reading
open TTY, "</dev/tty" or die $!;
$self->{tty_fd} = fileno(TTY);
$self->{pbot}->{select_handler}->add_reader(\*STDIN, sub { $self->stdin_reader(@_) });
if (not $self->{pbot}->{registry}->get_value('general', 'daemon')) {
open TTY, "</dev/tty" or die $!;
$self->{tty_fd} = fileno(TTY);
$self->{pbot}->{select_handler}->add_reader(\*STDIN, sub { $self->stdin_reader(@_) });
} else {
$self->{pbot}->{logger}->log("Starting in daemon mode.\n");
}
}
sub stdin_reader {