1

Implement !xkcd command

This commit is contained in:
eleksir
2021-03-08 17:26:58 +03:00
parent da7d61248d
commit eec7c1691a
2 changed files with 31 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ use kitty qw (kitty);
use lat qw (latAnswer);
use util qw (trim utf2sha1);
use weather qw (weather);
use xkcd qw (xkcd);
use version; our $VERSION = qw (1.0);
use Exporter qw(import);
@@ -197,6 +198,7 @@ ${csign}some_brew - выдать соответствующий на
${csign}ver | ${csign}version - написать что-то про версию ПО
${csign}версия - написать что-то про версию ПО
${csign}w город | ${csign}п город - погода в городе
${csign}xkcd - комикс-стрип с xkcb.ru
EOL
} elsif (substr ($text, 1) eq 'lat' || substr ($text, 1) eq 'лат') {
@@ -209,6 +211,8 @@ EOL
$reply = dig ($chattername);
} elsif (substr ($text, 1) eq 'fish' || substr ($text, 1) eq 'fisher' || substr ($text, 1) eq 'рыба' || substr ($text, 1) eq 'рыбка' || substr ($text, 1) eq 'рыбалка') {
$reply = fish ($chattername);
} elsif (substr ($text, 1) eq 'xkcd') {
$reply = xkcd ();
} elsif ((length ($text) >= 6 && (substr ($text, 1, 6) eq 'karma ' || substr ($text, 1, 6) eq 'карма ')) || substr ($text, 1) eq 'karma' || substr ($text, 1) eq 'карма') {
my $mytext = '';

27
lib/xkcd.pm Normal file
View File

@@ -0,0 +1,27 @@
package xkcd;
use 5.018;
use strict;
use warnings;
use utf8;
use open qw (:std :utf8);
use HTTP::Tiny;
use version; our $VERSION = qw (1.0);
use Exporter qw (import);
our @EXPORT_OK = qw (xkcd);
sub xkcd {
my $http = HTTP::Tiny->new (timeout => 5, max_redirect => 0);
my $r = $http->get ('https://xkcd.ru/random/');
if (defined $r->{headers} && defined $r->{headers}->{location} && $r->{headers}->{location} ne '') {
return sprintf 'https://xkcd.ru/i/%s_v1.png', substr ($r->{headers}->{location}, 1, -1);
}
return 'Комикс-стрип нарисовать не так-то просто :(';
}
1;
# vim: set ft=perl noet ai ts=4 sw=4 sts=4: