mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-20 02:49:49 +01:00
StdinReader: add general.daemon registry item; give stdin bot account botowner capability
This commit is contained in:
parent
58233293fb
commit
437da18ac7
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user