diff --git a/telegram.cfg b/telegram.cfg index f945909..a6e51eb 100644 --- a/telegram.cfg +++ b/telegram.cfg @@ -13,6 +13,8 @@ debug: 0 matchPattern: . #number of backlog lines sent when pattern matches in channel: backlog: 3 +#number of follow-up lines sent after sending a message +numfollowup: 0 #base-url for posted images #baseURL: http://hostname/~user/i2t #path to base-url in local filesystem diff --git a/telegram.pl b/telegram.pl index 3e36295..4aa45df 100644 --- a/telegram.pl +++ b/telegram.pl @@ -39,6 +39,7 @@ my $idletime; my $longpoll; +my $numfollowup; my $baseURL; my $localPath; @@ -49,6 +50,7 @@ my $last_poll = 0; my $last_ts = 0; +my $followup = 0; my $offset = -1; my %servers; # maps channels to servers my $last_target; @@ -97,7 +99,8 @@ ($;$) if (defined $srv) { if (length($text)) { $srv->command($cmd); - telegram_send_message($user, "->${chan}"); + $followup = $numfollowup; + telegram_send_message($user, "->${chan}".($followup?" (f'up: ".$followup.")":"")); } else { telegram_send_message($user, "${chan} on $srv->{tag} ".(defined($modifier)?"(${modifier}) ":"")."selected as new target."); if ($modifier eq "all") { @@ -153,7 +156,8 @@ ($;$) my $cmd = "msg ${target} ".$text; print $cmd if ($debug); $server->command($cmd); - telegram_send_message($user, "->${target}"); + $followup = $numfollowup; + telegram_send_message($user, "->${target}".($followup?" (f'up: ".$followup.")":"")); } } @@ -402,7 +406,11 @@ sub telegram_signal { my $text = "${from}: ${msg}"; - if (!$query && !grep(/$matchPattern/, $msg) && ((!defined($sendchan)) || $sendchan ne $target)) { + if ( !$query + && !grep(/$matchPattern/, $msg) + && ((!defined($sendchan)) || $sendchan ne $target) + && (!$followup || (!defined($last_target)) || $target ne $last_target) + ) { if ($backlog) { push @{$log->{$target}}, $text; shift @{$log->{$target}} if ($#{$log->{$target}} >= $backlog); @@ -410,6 +418,11 @@ sub telegram_signal { return; } + if ($followup && defined($last_target) && $target eq $last_target) { + $text = '('.$followup.') '.$text unless $query; + $followup--; + } + my $quiet = undef; $quiet = 1 if (!$query && !grep(/$matchPattern/, $msg)); @@ -469,6 +482,9 @@ sub telegram_timer { $backlog = $cfg->param('backlog') // 0; $backlog = int($backlog); +$numfollowup = $cfg->param('numfollowup') // 0; +$numfollowup = int($numfollowup); + $idletime = $cfg->param('idletime') // 300; $idletime = int($idletime);