3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 11:42:35 +01:00

Move creation of stdin admin to StdinReader

This commit is contained in:
Pragmatic Software 2020-01-23 20:47:18 -08:00
parent 918b6fee5d
commit c0ad02e6a3
2 changed files with 13 additions and 12 deletions

View File

@ -187,8 +187,8 @@ sub initialize {
$self->{event_dispatcher} = PBot::EventDispatcher->new(pbot => $self, %conf);
$self->{irchandlers} = PBot::IRCHandlers->new(pbot => $self, %conf);
$self->{select_handler} = PBot::SelectHandler->new(pbot => $self, %conf);
$self->{stdin_reader} = PBot::StdinReader->new(pbot => $self, %conf);
$self->{admins} = PBot::Admins->new(pbot => $self, filename => "$data_dir/admins", %conf);
$self->{stdin_reader} = PBot::StdinReader->new(pbot => $self, %conf);
$self->{bantracker} = PBot::BanTracker->new(pbot => $self, %conf);
$self->{lagchecker} = PBot::LagChecker->new(pbot => $self, %conf);
$self->{messagehistory} = PBot::MessageHistory->new(pbot => $self, filename => "$data_dir/message_history.sqlite3", %conf);
@ -214,11 +214,6 @@ sub initialize {
# load available plugins
$self->{plugins}->autoload(%conf);
# create implicit bot-admin account for bot
my $botnick = $self->{registry}->get_value('irc', 'botnick');
$self->{admins}->add_admin($botnick, '.*', "*!stdin\@pbot", 100, 'notused', 1);
$self->{admins}->login($botnick, "$botnick!stdin\@pbot", 'notused');
# start timer
$self->{timer}->start();
}

View File

@ -13,10 +13,7 @@ use POSIX qw(tcgetpgrp getpgrp); # to check whether process is in background or
use Carp ();
sub new {
if (ref($_[1]) eq 'HASH') {
Carp::croak("Options to StdinReader should be key/value pairs, not hash reference");
}
Carp::croak("Options to StdinReader should be key/value pairs, not hash reference") if ref($_[1]) eq 'HASH';
my ($class, %conf) = @_;
my $self = bless {}, $class;
$self->initialize(%conf);
@ -26,7 +23,16 @@ sub new {
sub initialize {
my ($self, %conf) = @_;
$self->{pbot} = delete $conf{pbot} // Carp::croak("Missing pbot reference in StdinReader");
$self->{pbot} = $conf{pbot} // Carp::croak("Missing pbot reference in StdinReader");
# create implicit bot-admin account for bot
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
if (not $self->{pbot}->{admins}->find_admin('.*', '*!stdin@pbot')) {
$self->{pbot}->{logger}->log("Adding stdin admin *!stdin\@pbot...\n");
$self->{pbot}->{admins}->add_admin($botnick, '.*', '*!stdin@pbot', 100, 'notused', 1);
$self->{pbot}->{admins}->login($botnick, "$botnick!stdin\@pbot", 'notused');
$self->{pbot}->{admins}->save_admins;
}
# used to check whether process is in background or foreground, for stdin reading
open TTY, "</dev/tty" or die $!;
@ -44,7 +50,7 @@ sub stdin_reader {
return if not $self->{foreground};
$self->{pbot}->{logger}->log("---------------------------------------------\n");
$self->{pbot}->{logger}->log("Read '$input' from STDIN\n");
$self->{pbot}->{logger}->log("Got STDIN: $input\n");
my ($from, $text);