Skip to content

Commit

Permalink
don't rely on messages to restart longpoll, use a timer instead
Browse files Browse the repository at this point in the history
  • Loading branch information
stargo committed Feb 8, 2018
1 parent 9f6db07 commit 2050d50
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions telegram.pl
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,6 @@ sub telegram_signal {
my $query = 0;
my $from = $nick;

telegram_getupdates(undef) if ($last_poll < (time() - ($longpoll * 2)));

if (!defined($target)) {
$target = $nick;
$query = 1;
Expand Down Expand Up @@ -457,6 +455,13 @@ sub telegram_idle {
$last_ts = time();
}

sub telegram_timer {
if ($last_poll < (time() - ($longpoll * 2))) {
print "Restarting telegram longpoll";
telegram_getupdates(undef);
}
}

$cfg = new Config::Simple($cfgfile) || die "Can't open ${cfgfile}: $!";
$token = $cfg->param('token') || die "No token defined in config!";
$user = $cfg->param('user') || die "No user defined in config!";
Expand All @@ -479,6 +484,7 @@ sub telegram_idle {
$debug = $cfg->param('debug');

telegram_getupdates(undef);
Irssi::timeout_add(10 * 1000, \&telegram_timer, undef);

Irssi::signal_add("message public", "telegram_signal");
Irssi::signal_add("message private", "telegram_signal_private");
Expand Down

0 comments on commit 2050d50

Please sign in to comment.