Skip to content

Instantly share code, notes, and snippets.

@bessarabov
Last active April 23, 2022 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bessarabov/aa8b45465e488bd75adcc834461954d5 to your computer and use it in GitHub Desktop.
Save bessarabov/aa8b45465e488bd75adcc834461954d5 to your computer and use it in GitHub Desktop.
commit 0a729b3acb0cb2f110002bef49ec43be20060c27
Author: Ivan Bessarabov <ivan@bessarabov.ru>
Date: Fri Apr 22 23:24:15 2022 +0300
Fixing telegram bot multiline commands
https://t.me/modernperl/206743
Alexander P, [22 Apr 2022, 22:44:37]:
@PerlBanjoBot
$ perl -E 'undef $/; say <> =~ tr/CG/CG/' <<EOF
ACgt
acGT
EOF
PerlBanjoBot, [22 Apr 2022, 22:44:39]:
0
https://PerlBanjo.com/d22538f4ae
Alexander P, [22 Apr 2022, 22:45:47]:
Huh. BanjoBot doesn't understand here-docs :)
diff --git a/telegram-bot/lib/Utils.pm b/telegram-bot/lib/Utils.pm
index fb434ed..68b2ec5 100644
--- a/telegram-bot/lib/Utils.pm
+++ b/telegram-bot/lib/Utils.pm
@@ -117,7 +117,7 @@ sub parse_telegram_request {
my $perl_code_or_command = $1;
- if ($perl_code_or_command =~ /^\$\s+(.*)/) {
+ if ($perl_code_or_command =~ /^\$\s+(.*)/ms) {
%answer = (
need_to_create_task => 1,
command => $1,
diff --git a/telegram-bot/t/parse_telegram_request.t b/telegram-bot/t/parse_telegram_request.t
index 0e5344a..2bb6202 100644
--- a/telegram-bot/t/parse_telegram_request.t
+++ b/telegram-bot/t/parse_telegram_request.t
@@ -7,7 +7,7 @@ use Test::More;
use Utils;
-plan tests => 12;
+plan tests => 13;
my @tests = (
{
@@ -247,6 +247,36 @@ ls',
},
test_name => qq(supergroup \@PerlBanjoBot\\n \$ perl -E "say 123"),
},
+ {
+ telegram_request => {
+ message => {
+ chat => {
+ id => 789,
+ type => 'supergroup',
+ },
+ from => {},
+ message_id => 38,
+ text => q(
+@PerlBanjoBot
+$ perl -E 'undef $/; say <> =~ tr/CG/CG/' <<EOF
+ACgt
+acGT
+EOF
+),
+ },
+ update_id => 4,
+ },
+ expected_answer => {
+ need_to_create_task => 1,
+ command => q(perl -E 'undef $/; say <> =~ tr/CG/CG/' <<EOF
+ACgt
+acGT
+EOF
+),
+ files => [],
+ },
+ test_name => qq(supergroup multiline),
+ },
{
telegram_request => {
'message' => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment