aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Ramos2019-06-25 13:05:17 +0200
committerGuillermo Ramos2019-06-25 13:05:17 +0200
commitd6f2506d29d78397944085e402421d01436d2a0a (patch)
tree56c0faaa9536b7e3466928206489d2b6a101a3d4
parent077112d7242df2d1a26d90506b23045c6a6eb4ab (diff)
downloadtgutils-d6f2506d29d78397944085e402421d01436d2a0a.tar.gz
tgserver uses TgLib::Api::get_updates
-rwxr-xr-xtgserver13
1 files changed, 9 insertions, 4 deletions
diff --git a/tgserver b/tgserver
index 9c6e89c..96e9b90 100755
--- a/tgserver
+++ b/tgserver
@@ -17,8 +17,9 @@ use FindBin;
use lib "$FindBin::Bin/lib";
use TgLib qw<fetch_token>;
-require TgLib::Logger;
require TgLib::Api;
+require TgLib::Cache;
+require TgLib::Logger;
my $TOKEN;
my $VERBOSE = 0;
@@ -36,9 +37,14 @@ $TOKEN ||= fetch_token() or
pod2usage(-message => "ERROR: Unable to get bot token ($!).\n",
-verbose => 99, -sections => "AUTHENTICATION");
+my $cache = TgLib::Cache->new($logger);
+my $api = TgLib::Api->new($TOKEN, $logger);
while (1) {
- open(my $recv, "-|", "$FindBin::Bin/tgrecv --token $TOKEN --auto-offset --timeout 100000");
- foreach my $update (@{decode_json <$recv>}) {
+ # FIXME magic timeout
+ foreach my $update (@{$api->get_updates(3600, $cache->offset)}) {
+ # Cache current offset
+ $cache->offset($update->{'update_id'}+1);
+
$logger->debug(sprintf "Update %s", Dumper($update));
my $text = $update->{'message'}{'text'};
my $chat_id = $update->{'message'}{'chat'}{'id'};
@@ -60,7 +66,6 @@ while (1) {
$logger->warn("Empty response, skipping\n");
}
}
- close($recv);
}
__END__