User:AnomieBOT/source/read-command.pl

#!/usr/bin/perl -w

use strict;

use Cwd;
use File::Basename;
use lib File::Basename::dirname( Cwd::realpath( __FILE__ ) );
use AnomieBOT::API;

my $botnum = shift // die "USAGE: $0 botnum";

my ($api, $cmdfile);
if ( $botnum eq 'updater' ) {
    $api = AnomieBOT::API->new("conf.ini", 1, { db => 0 });
    $cmdfile = 'cache:command:AnomieBOT-updater';
} else {
    $api = AnomieBOT::API->new("conf.ini", $botnum, { db => 0 });
    $cmdfile = $api->{'commandfile'};
}
my $cmd = $api->read_command( $cmdfile, qr/^/ );
print "$cmd\n" if defined $cmd;