aboutsummaryrefslogtreecommitdiff
path: root/lib/TgLib.pm
diff options
context:
space:
mode:
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;