aboutsummaryrefslogtreecommitdiff
path: root/lib/TgLib.pm
diff options
context:
space:
mode:
authorGuillermo Ramos2019-06-24 13:10:02 +0200
committerGuillermo Ramos2019-06-24 17:39:53 +0200
commit57f8e009519b305294d002784967239e7a41ef5e (patch)
tree1f76ce42d4dc96e3561dbef035631fdef008a704 /lib/TgLib.pm
parent47fb4fc02407def9d9b19a2746983b8c65937e3f (diff)
downloadtgutils-57f8e009519b305294d002784967239e7a41ef5e.tar.gz
TgLib::fetch_token
Diffstat (limited to 'lib/TgLib.pm')
-rw-r--r--lib/TgLib.pm16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/TgLib.pm b/lib/TgLib.pm
index 9be77d7..192d28a 100644
--- a/lib/TgLib.pm
+++ b/lib/TgLib.pm
@@ -1,6 +1,20 @@
package TgLib;
+use TgLib::Env qw<$CONFIG_HOME>;
+
use parent qw<Exporter>;
-our @EXPORT = qw<>;
+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]+:[a-zA-Z0-9]+$/ or die "Invalid bot token ($token)";
+ return $token;
+}
1;