1

Fix !drink command

This commit is contained in:
eleksir
2022-06-21 23:30:16 +03:00
parent 4325061848
commit 7787be73b3

View File

@@ -27,7 +27,7 @@ sub Drink {
my $drinkCallBack = sub { my $drinkCallBack = sub {
my $ret; my $ret;
my ($dayNum, $monthNum) = (localtime ())[3, 4]; my ($dayNum, $monthNum) = (localtime ())[3, 4];
my $url = sprintf 'https://kakoysegodnyaprazdnik.ru/baza/%s/%s', $MONTH[$monthNum], $dayNum; my $url = 'https://prazdniki-segodnya.ru/';
my $r; my $r;
for (1..3) { for (1..3) {
@@ -42,28 +42,32 @@ sub Drink {
} }
if ($r->{success}) { if ($r->{success}) {
# TODO: Handle unexpected content
my $p = HTML::TokeParser->new (\$r->{content}); my $p = HTML::TokeParser->new (\$r->{content});
my @a; my @a;
my @holiday; my %holiday;
do { do {
$#a = -1; $#a = -1;
@a = $p->get_tag ('span'); ## no critic (Variables::RequireLocalizedPunctuationVars) @a = $p->get_tag ('div'); ## no critic (Variables::RequireLocalizedPunctuationVars)
if ($#{$a[0]} > 2 && defined $a[0][1]->{itemprop} && $a[0][1]->{itemprop} eq 'text') { if ($#{$a[0]} > 2) {
push @holiday,'* ' . decode ('UTF-8', $p->get_trimmed_text ('/span')); my @shitty_array = $a[0];
foreach my $item (@shitty_array) {
if (ref $item) {
foreach my $item1 (@{$item}) {
my %h = eval { %{$item1} };
if (defined ($h{class}) && $h{class} eq 'list-group-item text-monospace') {
$holiday {'* ' . decode ('UTF-8', $p->get_trimmed_text ('/div'))} = 1;
}
}
}
}
} }
} while ($#{$a[0]} > 1); } while ($#{$a[0]} > 1);
if ($#holiday > 0) { if (int (keys %holiday) > 0) {
# cut off something weird, definely not a "holyday" $ret = join "\n", sort (keys %holiday);
$#holiday = $#holiday - 1;
}
if ($#holiday > 0) {
$ret = join "\n", @holiday;
} }
} else { } else {
$log->warn (sprintf '[WARN] Server return status %s with message: %s', $r->{status}, $r->{reason}); $log->warn (sprintf '[WARN] Server return status %s with message: %s', $r->{status}, $r->{reason});