1 Commits
v1.3 ... v1.4

Author SHA1 Message Date
eleksir
b6a4aaa4c1 Fix handling formating for telegram 2022-04-17 17:09:53 +03:00
2 changed files with 33 additions and 36 deletions

View File

@@ -64,80 +64,77 @@ my $parse_message = sub {
$log->debug ('[DEBUG] Incoming message ' . Dumper($m)); $log->debug ('[DEBUG] Incoming message ' . Dumper($m));
if (substr ($m->{message}, 1) eq 'buni') { if (substr ($m->{message}, 1) eq 'buni') {
if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
$reply = sprintf '[buni](%s)', Buni ();
} else {
$reply = Buni (); $reply = Buni ();
}
} elsif (substr ($m->{message}, 1) eq 'anek' || substr ($m->{message}, 1) eq 'анек' || substr ($m->{message}, 1) eq 'анекдот') { } elsif (substr ($m->{message}, 1) eq 'anek' || substr ($m->{message}, 1) eq 'анек' || substr ($m->{message}, 1) eq 'анекдот') {
if ($m->{plugin} eq 'telegram') { if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
$reply = "```\n" . Anek () . "\n```"; $reply = "```\n" . Anek () . "\n```";
$answer->{misc}->{msg_format} = 1;
} else { } else {
$reply = Anek (); $reply = Anek ();
} }
} elsif (substr ($m->{message}, 1) eq 'cat' || substr ($m->{message}, 1) eq 'кис') { } elsif (substr ($m->{message}, 1) eq 'cat' || substr ($m->{message}, 1) eq 'кис') {
if ($m->{plugin} eq 'telegram') { if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
my @cats = ('龴ↀ◡ↀ龴', '=^..^=', '≧◔◡◔≦ ','^ↀᴥↀ^'); my @cats = ('龴ↀ◡ↀ龴', '=^..^=', '≧◔◡◔≦ ','^ↀᴥↀ^');
my $cat = Kitty (); $reply = sprintf '[%s](%s)', $cats[irand ($#cats + 1)], Kitty ();
$reply = sprintf '[%s](%s)', $cats[irand ($#cats + 1)], $cat;
$answer->{misc}->{msg_format} = 1;
} else { } else {
$reply = Kitty (); $reply = Kitty ();
} }
} elsif (substr ($m->{message}, 1) eq 'drink' || substr ($m->{message}, 1) eq 'праздник') { } elsif (substr ($m->{message}, 1) eq 'drink' || substr ($m->{message}, 1) eq 'праздник') {
$reply = Drink (); $reply = Drink ();
} elsif (substr ($m->{message}, 1) eq 'fox' || substr ($m->{message}, 1) eq 'лис') { } elsif (substr ($m->{message}, 1) eq 'fox' || substr ($m->{message}, 1) eq 'лис') {
if ($m->{plugin} eq 'telegram') { if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
my $fox = Fox (); $reply = sprintf '[-^^,--,~](%s)', Fox ();
$reply = sprintf '[-^^,--,~](%s)', $fox;
$answer->{misc}->{msg_format} = 1;
} else { } else {
$reply = Fox (); $reply = Fox ();
} }
} elsif (substr ($m->{message}, 1) eq 'frog' || substr ($m->{message}, 1) eq 'лягушка') { } elsif (substr ($m->{message}, 1) eq 'frog' || substr ($m->{message}, 1) eq 'лягушка') {
if ($m->{plugin} eq 'telegram') { if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
my @art = qw (frog toad лягушка); my @art = qw (frog toad лягушка);
my $frog = Frog (); $reply = sprintf '[%s](%s)', $art [irand ($#art + 1)], Frog ();
$reply = sprintf '[%s](%s)', $art [irand ($#art + 1)], $frog;
$answer->{misc}->{msg_format} = 1;
} else { } else {
$reply = Frog (); $reply = Frog ();
} }
} elsif (substr ($m->{message}, 1) eq 'horse' || substr ($m->{message}, 1) eq 'лошадь' || substr ($m->{message}, 1) eq 'лошадка') { } elsif (substr ($m->{message}, 1) eq 'horse' || substr ($m->{message}, 1) eq 'лошадь' || substr ($m->{message}, 1) eq 'лошадка') {
if ($m->{plugin} eq 'telegram') { if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
my @art = qw (horse лошадь лошадка); my @art = qw (horse лошадь лошадка);
my $horse = Horse (); $reply = sprintf '[%s](%s)', $art [irand ($#art + 1)], Horse ();
$reply = sprintf '[%s](%s)', $art [irand ($#art + 1)], $horse;
$answer->{misc}->{msg_format} = 1;
} else { } else {
$reply = Horse (); $reply = Horse ();
} }
} elsif (substr ($m->{message}, 1) eq 'monkeyuser') { } elsif (substr ($m->{message}, 1) eq 'monkeyuser') {
if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
$reply = sprintf '[monkeyuser](%s)', Monkeyuser ();
} else {
$reply = Monkeyuser (); $reply = Monkeyuser ();
}
} elsif (substr ($m->{message}, 1) eq 'owl' || substr ($m->{message}, 1) eq 'сова' || substr ($m->{message}, 1) eq 'сыч') { } elsif (substr ($m->{message}, 1) eq 'owl' || substr ($m->{message}, 1) eq 'сова' || substr ($m->{message}, 1) eq 'сыч') {
if ($m->{plugin} eq 'telegram') { if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
my $owl = Owl (); $reply = sprintf '[{ O v O }](%s)', Owl ();
$reply = sprintf '[{ O v O }](%s)', $owl;
$answer->{misc}->{msg_format} = 1;
} else { } else {
$reply = Owl (); $reply = Owl ();
} }
} elsif (substr ($m->{message}, 1) eq 'rabbit' || substr ($m->{message}, 1) eq 'bunny' || substr ($m->{message}, 1) eq 'кролик') { } elsif (substr ($m->{message}, 1) eq 'rabbit' || substr ($m->{message}, 1) eq 'bunny' || substr ($m->{message}, 1) eq 'кролик') {
if ($m->{plugin} eq 'telegram') { if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
my $rabbit = Rabbit (); $reply = sprintf '[(\_/)](%s)', Rabbit ();
$reply = sprintf '[(\_/)](%s)', $rabbit;
$answer->{misc}->{msg_format} = 1;
} else { } else {
$reply = Rabbit (); $reply = Rabbit ();
} }
} elsif (substr ($m->{message}, 1) eq 'snail' || substr ($m->{message}, 1) eq 'улитка') { } elsif (substr ($m->{message}, 1) eq 'snail' || substr ($m->{message}, 1) eq 'улитка') {
if ($m->{plugin} eq 'telegram') { if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
my @art = qw ('-'_@_ @╜ @_'-'); my @art = qw ('-'_@_ @╜ @_'-');
my $snail = Snail (); $reply = sprintf '[%s](%s)', $art [irand ($#art + 1)], Snail ();
$reply = sprintf '[%s](%s)', $art [irand ($#art + 1)], $snail;
$answer->{misc}->{msg_format} = 1;
} else { } else {
$reply = Snail (); $reply = Snail ();
} }
} elsif (substr ($m->{message}, 1) eq 'xkcd') { } elsif (substr ($m->{message}, 1) eq 'xkcd') {
if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
$reply = sprintf '[xkcd](%s)', Xkcd ();
} else {
$reply = Xkcd (); $reply = Xkcd ();
}
} elsif (substr ($m->{message}, 1, 2) eq 'w ' || substr ($m->{message}, 1, 2) eq 'п ') { } elsif (substr ($m->{message}, 1, 2) eq 'w ' || substr ($m->{message}, 1, 2) eq 'п ') {
my $city = substr $m->{message}, 2; my $city = substr $m->{message}, 2;
$reply = Weather ($city); $reply = Weather ($city);

View File

@@ -176,7 +176,7 @@ sub Buni {
@a = $p->get_tag('meta'); ## no critic (Variables::RequireLocalizedPunctuationVars) @a = $p->get_tag('meta'); ## no critic (Variables::RequireLocalizedPunctuationVars)
if (defined $a[0][1]->{property} && $a[0][1]->{property} eq 'og:image') { if (defined $a[0][1]->{property} && $a[0][1]->{property} eq 'og:image') {
$ret = sprintf '[buni](%s)', $a[0][1]->{content}; $ret = $a[0][1]->{content};
last; last;
} }
@@ -314,7 +314,7 @@ sub Monkeyuser {
} while ($#{$a[0]} > 1); } while ($#{$a[0]} > 1);
if ($#link > 0) { if ($#link > 0) {
$ret = sprintf '[MonkeyUser](https://www.monkeyuser.com%s)', $link [irand (1 + $#link)]; $ret = sprintf 'https://www.monkeyuser.com%s', $link [irand (1 + $#link)];
} }
} else { } else {
$log->warn (sprintf '[WARN] MonkeyUser server return status %s with message: %s', $r->{status}, $r->{reason}); $log->warn (sprintf '[WARN] MonkeyUser server return status %s with message: %s', $r->{status}, $r->{reason});
@@ -536,7 +536,7 @@ sub Xkcd {
} while ($c < 3 || $status >= 404); } while ($c < 3 || $status >= 404);
if ($status == 200) { if ($status == 200) {
return sprintf '[xkcd.ru](%s)', $location; return $location;
} }
return 'Комикс-стрип нарисовать не так-то просто :('; return 'Комикс-стрип нарисовать не так-то просто :(';