Skip to content

Commit

Permalink
Add follow-up functionality
Browse files Browse the repository at this point in the history
If you send from telegram to IRC, will give you the next
<numfollowup> replies from the target.

Might also combine this with $sendchan by giving the number
of follow-ups as a modifier (instead of 'all')?

Signed-off-by: knilch <[email protected]>
  • Loading branch information
knilch0r committed Mar 11, 2018
1 parent 5efb6b6 commit 81bead8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions telegram.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 19 additions & 3 deletions telegram.pl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

my $idletime;
my $longpoll;
my $numfollowup;

my $baseURL;
my $localPath;
Expand All @@ -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;
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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.")":""));
}
}

Expand Down Expand Up @@ -402,14 +406,23 @@ 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);
}
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));

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 81bead8

Please sign in to comment.