]> iEval git - app-statsbot.git/blobdiff - lib/App/Statsbot.pm
Support configuration via the environment
[app-statsbot.git] / lib / App / Statsbot.pm
index 5c0ab080450ad064fdc6f0339c941a719177a167..fcc79594eefc2656742758b52de94af9b3957aa3 100644 (file)
@@ -4,7 +4,7 @@ use 5.014000;
 use strict;
 use warnings;
 
-our $VERSION = '0.001001';
+our $VERSION = '0.001002';
 
 use POE;
 use POE::Component::IRC::State;
@@ -31,6 +31,15 @@ our $SSL = '';
 our @CHANNELS;
 our $DB = '/var/lib/statsbot/db';
 
+{
+       my %cfg = (debug => \$DEBUG, tick => \$TICK, nickname => \$NICKNAME, server => \$SERVER, port => \$PORT, ssl => \$SSL, channels => \@CHANNELS, db => \$DB);
+       for my $var (keys %cfg) {
+               my $key = "STATSBOT_\U$var";
+               ${$cfg{$var}} = $ENV{$key} if exists $ENV{$key} && ref $cfg{$var} eq 'SCALAR';
+               @{$cfg{$var}} = split ' ', $ENV{$key} if exists $ENV{$key} && ref $cfg{$var} eq 'ARRAY';
+       }
+}
+
 my $dbh;
 my $insert;
 my $update;
@@ -95,6 +104,8 @@ sub bot_start{ ## no critic (RequireArgUnpacking)
        $_[KERNEL]->delay(tick => $TICK);
 
        $irc->plugin_add(CTCP => POE::Component::IRC::Plugin::CTCP->new(
+               version => "Statsbot/$VERSION",
+               source => 'https://metacpan.org/pod/App::Statsbot',
                userinfo => 'A bot which keeps logs and computes channel statistics',
                clientinfo => 'PING VERSION CLIENTINFO USERINFO SOURCE',
        ));
@@ -127,10 +138,10 @@ sub on_public{
        my ($targets,$message)=@_[ARG1,ARG2];
        my $botnick = _nick_name;
 
-       if ($message =~ /(?:$botnick[:,])?\s*!?help\s*(.*)/) {
-               _yield(privmsg => $targets, "Try !presence username interval [truncate]");
-               _yield(privmsg => $targets, "For example, !presence mgv '2 days'");
-               _yield(privmsg => $targets, "or !presence mgv '1 year' 4");
+       if ($message =~ /(?:$botnick[:,])?\s*!?help\s*(.*)/sx) {
+               _yield(privmsg => $targets, 'Try !presence username interval [truncate]');
+               _yield(privmsg => $targets, q/For example, !presence mgv '2 days'/);
+               _yield(privmsg => $targets, q/or !presence mgv '1 year' 4/);
                return;
        }
 
@@ -196,6 +207,11 @@ a channel. It is able to answer queries of the form "In the last <time
 interval>, how much time did <nick> spend in this channel?".
 
 It is configured via global variables in the App::Statsbot package.
+These variables are initialized from environment variables with names
+of the form STATSBOT_DEBUG, STATSBOT_TICK, etc. In the case of array
+variables, the environment variable is treated as a space separated
+list. Each configuration variable has a default value used when it is
+not set explicitly or via the environment.
 
 =over
 
This page took 0.025635 seconds and 4 git commands to generate.