1

Compare commits

..

2 Commits

Author SHA1 Message Date
eleksir
eec7c1691a Implement !xkcd command 2021-03-08 17:26:58 +03:00
eleksir
da7d61248d Implement !fox !лис commands 2021-03-08 17:25:21 +03:00
3 changed files with 90 additions and 0 deletions

View File

@@ -12,12 +12,14 @@ use archeologist qw (dig);
use conf qw (loadConf);
use fisher qw (fish);
use fortune qw (fortune);
use fox qw (fox);
use friday qw (friday);
use karma qw (karmaGet);
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);
@@ -185,6 +187,7 @@ ${csign}fish | ${csign}fisher - порыбачить
${csign}рыба | ${csign}рыбка | ${csign}рыбалка - заняться археологией
${csign}f | ${csign}ф - рандомная фраза из сборника цитат fortune_mod
${csign}fortune | ${csign}фортунка - рандомная фраза из сборника цитат fortune_mod
${csign}fox | ${csign}лис - лисичка
${csign}friday | ${csign}пятница - а не пятница ли сегодня?
${csign}karma фраза - посмотреть карму фразы
${csign}карма фраза - посмотреть карму фразы
@@ -195,16 +198,21 @@ ${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 'лат') {
$reply = latAnswer ();
} elsif (substr ($text, 1) eq 'cat' || substr ($text, 1) eq 'кис') {
$reply = kitty ();
} elsif (substr ($text, 1) eq 'fox' || substr ($text, 1) eq 'лис') {
$reply = fox ();
} elsif (substr ($text, 1) eq 'dig' || substr ($text, 1) eq 'копать') {
$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 = '';

55
lib/fox.pm Normal file
View File

@@ -0,0 +1,55 @@
package fox;
use 5.018;
use strict;
use warnings;
use utf8;
use open qw (:std :utf8);
use English qw ( -no_match_vars );
use Carp qw (carp);
use JSON::XS;
use HTTP::Tiny;
use vars qw/$VERSION/;
use Exporter qw (import);
our @EXPORT_OK = qw (fox);
$VERSION = '1.0';
sub fox {
my $r;
my $ret = 'Нету лисичек, все разбежались.';
for (1..3) {
my $http = HTTP::Tiny->new (timeout => 3);
$r = $http->get ('https://randomfox.ca/floof/');
if ($r->{success}) {
last;
}
sleep 2;
}
if ($r->{success}) {
my $jfox = eval {
decode_json ($r->{content})
};
unless (defined $jfox) {
cluck "[ERROR] Unable to decode JSON: $EVAL_ERROR";
} else {
if ($jfox->{image}) {
$jfox->{image} =~ s/\\//xmsg;
$ret = $jfox->{image};
}
}
} else {
cluck sprintf 'Server return status %s with message: %s', $r->{status}, $r->{reason};
}
return $ret;
}
1;
# vim: set ft=perl noet ai ts=4 sw=4 sts=4:

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: