Implement !fox !лис commands
This commit is contained in:
@@ -12,6 +12,7 @@ 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);
|
||||
@@ -185,6 +186,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}карма фраза - посмотреть карму фразы
|
||||
@@ -201,6 +203,8 @@ EOL
|
||||
$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 'рыбалка') {
|
||||
|
||||
55
lib/fox.pm
Normal file
55
lib/fox.pm
Normal 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:
|
||||
Reference in New Issue
Block a user