aboutsummaryrefslogtreecommitdiff
path: root/lib/TgLib.pm
blob: 76316048a9d57a1cfa3f356e094746f1020fbc59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package TgLib;

use TgLib::Env qw<$CONFIG_HOME>;

use parent qw<Exporter>;
our @EXPORT = qw<fetch_token>;

sub fetch_token {
    my $token = $ENV{'TGUTILS_TOKEN'};
    unless ($token) {
        open(my $cfg, "<", "$CONFIG_HOME/tgutils_token") or return;
        $token = <$cfg>;
        chomp $token;
        close $cfg;
    }
    $token =~ /^[0-9]{9}:[a-zA-Z0-9_-]{35}$/ or die "Invalid bot token ($token)";
    return $token;
}

1;