Jump to content

User:AnomieBOT/source/show-pending-commands.pl

From Wikipedia, the free encyclopedia
#!/usr/bin/perl -w

use strict;

my @rows = ();

use Cwd;
use File::Basename;
use lib File::Basename::dirname( Cwd::realpath( __FILE__ ) );
use AnomieBOT::API;
open(X, "<:utf8", "conf.ini") or die "Could not open conf.ini: $!\n";
while(<X>){
    next unless /^\[bot (\d+)\]\s*$/o;
    my $botnum = $1;
    my $api = AnomieBOT::API->new("conf.ini", $botnum, { db => 0 });
    my $file = $api->{'commandfile'};
    my $cmd = $api->read_command( $file, qr/^/ ) // '<none>';
    push @rows, [ $botnum, $file, $cmd ];
    $api->DESTROY;
    $api = undef;
}

my $api = AnomieBOT::API->new("conf.ini", 1, { db => 0 });
my $file = 'cache:command:AnomieBOT-updater';
my $cmd = $api->read_command( $file, qr/^/ ) // '<none>';
push @rows, [ 'updater', $file, $cmd ];

my @l = (0,0);
for my $row (@rows) {
    $l[0] = length($row->[0]) if length($row->[0]) > $l[0];
    $l[1] = length($row->[1]) if length($row->[1]) > $l[1];
}

my $fmt = '%-'.$l[0].'s  %-'.$l[1]."s  %s\n";
for my $row (@rows) {
    printf $fmt, @$row;
}