Fix !drink for newer perl, also delete unused/obsolete code
This commit is contained in:
@@ -254,7 +254,7 @@ sub Drink {
|
|||||||
if ($r->is_success) {
|
if ($r->is_success) {
|
||||||
my $p = HTML::TokeParser->new(\$r->body);
|
my $p = HTML::TokeParser->new(\$r->body);
|
||||||
my @a;
|
my @a;
|
||||||
my %holyday;
|
my %holiday;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$#a = -1;
|
$#a = -1;
|
||||||
@@ -268,7 +268,7 @@ sub Drink {
|
|||||||
my %h = eval { %{$item1} };
|
my %h = eval { %{$item1} };
|
||||||
|
|
||||||
if (defined ($h{class}) && $h{class} eq 'list-group-item text-monospace') {
|
if (defined ($h{class}) && $h{class} eq 'list-group-item text-monospace') {
|
||||||
$holyday {'* ' . decode ('UTF-8', $p->get_trimmed_text ('/div'))} = 1;
|
$holiday {'* ' . decode ('UTF-8', $p->get_trimmed_text ('/div'))} = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,8 +276,8 @@ sub Drink {
|
|||||||
}
|
}
|
||||||
} while ($#{$a[0]} > 1);
|
} while ($#{$a[0]} > 1);
|
||||||
|
|
||||||
if (int (keys (%holyday)) > 0) {
|
if (int (keys (%holiday)) > 0) {
|
||||||
$ret = join "\n", sort (keys ($holyday));
|
$ret = join "\n", sort (keys (%holiday));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$log->warn (sprintf '[WARN] prazdniki-segodnya.ru server return status %s with message: %s', $r->code, $r->message);
|
$log->warn (sprintf '[WARN] prazdniki-segodnya.ru server return status %s with message: %s', $r->code, $r->message);
|
||||||
@@ -286,98 +286,6 @@ sub Drink {
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub Drink1 {
|
|
||||||
my $r;
|
|
||||||
my $ret = 'Не знаю праздников - вджобываю весь день на шахтах, как проклятая.';
|
|
||||||
my ($dayNum, $monthNum) = (localtime ())[3, 4];
|
|
||||||
my $url = sprintf 'https://kakoysegodnyaprazdnik.ru/baza/%s/%s', $MONTH[$monthNum], $dayNum;
|
|
||||||
|
|
||||||
# Those POSIX assholes just forgot to add unix timestamps without TZ offset, so...
|
|
||||||
my ($mday, $mon, $year) = (gmtime ())[3, 4, 5];
|
|
||||||
my $offset = strftime ('%z', gmtime ());
|
|
||||||
my $offsetMinutes = (substr $offset, -2) * 60;
|
|
||||||
my $offsetHours = (substr $offset, 1, 2) * 60 * 60;
|
|
||||||
my $offsetSign;
|
|
||||||
|
|
||||||
if ((substr $offset, 0, 1) eq '+') {
|
|
||||||
$offsetSign = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $expirationDate = DateTime->new (
|
|
||||||
year => $year + 1900,
|
|
||||||
month => $mon + 1,
|
|
||||||
day => $mday,
|
|
||||||
hour => 0,
|
|
||||||
minute => 0,
|
|
||||||
second => 0,
|
|
||||||
)->add (days => 1)->strftime ('%s');
|
|
||||||
|
|
||||||
if ((substr $offset, 0, 1) eq '+') {
|
|
||||||
$expirationDate = $expirationDate - $offsetHours - $offsetMinutes;
|
|
||||||
} else {
|
|
||||||
$expirationDate = $expirationDate + $offsetHours + $offsetMinutes;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (1..3) {
|
|
||||||
my $ua = Mojo::UserAgent::Cached->new->connect_timeout (3);
|
|
||||||
$ua->cache_agent(
|
|
||||||
CHI->new (
|
|
||||||
driver => 'BerkeleyDB',
|
|
||||||
root_dir => $cachedir,
|
|
||||||
namespace => __PACKAGE__,
|
|
||||||
expires_at => $expirationDate,
|
|
||||||
expires_on_backend => 1,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
# just to make Mojo::UserAgent::Cached happy
|
|
||||||
$ua->logger (Mojo::Log->new (path => File::Spec->devnull, level => 'error'));
|
|
||||||
my $useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36';
|
|
||||||
|
|
||||||
if ($#useragents > 0) {
|
|
||||||
$useragent = $useragents [ (localtime ()) [3] ];
|
|
||||||
}
|
|
||||||
|
|
||||||
$ua->transactor->name ($useragent);
|
|
||||||
|
|
||||||
$r = $ua->get ($url => {'Accept-Language' => 'ru-RU', 'Accept-Charset' => 'utf-8'})->result;
|
|
||||||
|
|
||||||
if ($r->is_success) {
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($r->is_success) {
|
|
||||||
my $p = HTML::TokeParser->new(\$r->body);
|
|
||||||
my @a;
|
|
||||||
my @holyday;
|
|
||||||
|
|
||||||
do {
|
|
||||||
$#a = -1;
|
|
||||||
@a = $p->get_tag ('span'); ## no critic (Variables::RequireLocalizedPunctuationVars)
|
|
||||||
|
|
||||||
if ($#{$a[0]} > 2 && defined $a[0][1]->{itemprop} && $a[0][1]->{itemprop} eq 'text') {
|
|
||||||
push @holyday,'* ' . decode ('UTF-8', $p->get_trimmed_text ('/span'));
|
|
||||||
}
|
|
||||||
|
|
||||||
} while ($#{$a[0]} > 1);
|
|
||||||
|
|
||||||
if ($#holyday > 0) {
|
|
||||||
# cut off something weird, definely not a "holyday"
|
|
||||||
$#holyday = $#holyday - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($#holyday > 0) {
|
|
||||||
$ret = join "\n", @holyday;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$log->warn (sprintf '[WARN] Kakoysegodnyaprazdnik server return status %s with message: %s', $r->code, $r->message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub Monkeyuser {
|
sub Monkeyuser {
|
||||||
my $r;
|
my $r;
|
||||||
my $ret = 'Нету Monkey User-ов, они все спрятались.';
|
my $ret = 'Нету Monkey User-ов, они все спрятались.';
|
||||||
|
|||||||
Reference in New Issue
Block a user