Skip to content

Commit

Permalink
add channel modifier to get all messages in the current channel
Browse files Browse the repository at this point in the history
select a channel with #channel,all to activate this feature
(will also be sent in the keyboard). "," is an invalid character
for IRC channels, so this should not interfere with real channel
names.
  • Loading branch information
stargo committed Jan 7, 2018
1 parent 931cc35 commit c9e341a
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions telegram.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
my %servers; # maps channels to servers
my $last_target;
my $last_server;
my $sendchan = undef;

sub telegram_getupdates($);
sub telegram_send_message($$;$);
Expand All @@ -64,6 +65,13 @@ ($;$)
# post in specific channel
(my $chan, my $text) = split(/ /, $text, 2);
$chan =~ s/^\@//;

my $modifier;
if ($chan =~ m/^(#.+),(.+)$/) {
$chan = $1;
$modifier = $2;
}

my $cmd = "msg ${chan} ".$text;
print $cmd if ($debug);
my $srv = $servers{$chan};
Expand All @@ -87,7 +95,12 @@ ($;$)
$srv->command($cmd);
telegram_send_message($user, "->${chan}");
} else {
telegram_send_message($user, "${chan} on $srv->{tag} selected as new target.");
telegram_send_message($user, "${chan} on $srv->{tag} ".(defined($modifier)?"(${modifier}) ":"")."selected as new target.");
if ($modifier eq "all") {
$sendchan = $chan;
} else {
$sendchan = undef;
}
}
$last_target = $chan;
$last_server = $srv;
Expand Down Expand Up @@ -351,7 +364,7 @@ sub telegram_signal {
print "Idle: " . (time() - $last_ts) if ($debug);
return if ((time() - $last_ts < $idletime) && !$debug);

return if (!$query && !grep(/$matchPattern/, $msg));
return if (!$query && !grep(/$matchPattern/, $msg) && ((!defined($sendchan)) || $sendchan ne $target));

my $reply_markup;
if ((!defined($last_target)) ||
Expand All @@ -360,12 +373,14 @@ sub telegram_signal {
($server->{tag} ne $last_server->{tag})) {
my $dst = $target;
$dst = '@'.$dst if ($dst !~ m/^#/);
my @kbd = [{text => $dst}];
push @{$kbd[0]}, {text => $dst.",all"} if ($dst =~ m/^#/);
$reply_markup = {
keyboard => [
[{text => $dst}],
],
@kbd,
],
one_time_keyboard => JSON::true,
};
};
}

telegram_send_message($user, "${from}: ${msg}", $reply_markup);
Expand Down

0 comments on commit c9e341a

Please sign in to comment.