aboutsummaryrefslogtreecommitdiff
path: root/tgrecv
diff options
context:
space:
mode:
authorGuillermo Ramos2019-06-24 13:10:02 +0200
committerGuillermo Ramos2019-06-24 17:39:53 +0200
commit57f8e009519b305294d002784967239e7a41ef5e (patch)
tree1f76ce42d4dc96e3561dbef035631fdef008a704 /tgrecv
parent47fb4fc02407def9d9b19a2746983b8c65937e3f (diff)
downloadtgutils-57f8e009519b305294d002784967239e7a41ef5e.tar.gz
TgLib::fetch_token
Diffstat (limited to 'tgrecv')
-rwxr-xr-xtgrecv19
1 files changed, 4 insertions, 15 deletions
diff --git a/tgrecv b/tgrecv
index 3fa9dbf..2c612aa 100755
--- a/tgrecv
+++ b/tgrecv
@@ -20,6 +20,7 @@ use JSON qw<encode_json decode_json>;
# Local modules
use FindBin;
use lib "$FindBin::Bin/lib";
+use TgLib qw<fetch_token>;
use TgLib::Env qw<$HOME $CONFIG_HOME $CACHE_HOME>;
use TgLib::Cache;
@@ -40,22 +41,10 @@ GetOptions("token=s" => \$TOKEN,
"help" => \$HELP);
pod2usage(-verbose => $VERBOSE+1) if $HELP;
-# If token was not specified in CLI, try to get it from ENV
-$TOKEN ||= $ENV{'TGUTILS_TOKEN'};
-
-# If still no token, try to get it from ~/.config/tgutils_token
-unless ($TOKEN) {
- my $CONFIG = "$CONFIG_HOME/tgutils_token";
- open(my $cfg, "<", $CONFIG) or
- pod2usage(-message => "ERROR: Unable to get bot token ($CONFIG: $!).\n",
+# If token was not specified in CLI, get it from ENV/file
+$TOKEN ||= fetch_token() or
+ pod2usage(-message => "ERROR: Unable to get bot token ($!).\n",
-verbose => 99, -sections => "AUTHENTICATION");
- $TOKEN = <$cfg>;
- chomp $TOKEN;
- close $cfg;
-}
-
-# Sanity check
-$TOKEN =~ /^[0-9]+:[a-zA-Z0-9]+$/ or die "Invalid bot token ($TOKEN)";
my $cache = TgLib::Cache->new;
print STDERR "Using cache:\n", Dumper($cache), "\n" if $VERBOSE > 1;