Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f25a4d9ea3 | ||
|
|
3d6be5ae04 | ||
|
|
4c6a1ea4cd | ||
|
|
a891c7ed6f |
2
cpanfile
2
cpanfile
@@ -23,7 +23,7 @@ requires 'Log::Any::Adapter', '==1.710';
|
||||
requires 'Log::Any::For::Std', '==0.05';
|
||||
requires 'Math::Random::Secure', '==0.080001';
|
||||
requires 'MIME::Base64', '==3.16';
|
||||
requires 'Mojolicious', '==9.24';
|
||||
requires 'Mojolicious', '==9.26';
|
||||
requires 'Mojo::IOLoop::Signal', '==0.003';
|
||||
# Чтобы заткнуть Mojo::UserAgent::Cached
|
||||
requires 'Mojo::Log', '0';
|
||||
|
||||
@@ -98,17 +98,17 @@ my $parse_message = sub {
|
||||
$answer->{misc}->{username} = 'user';
|
||||
}
|
||||
|
||||
if (length $m->{message} <= length $answer->{csign}) {
|
||||
if (length $m->{message} <= length $answer->{misc}->{csign}) {
|
||||
$log->info (sprintf 'Unable to process unknown message: %s', $m->{message});
|
||||
return;
|
||||
}
|
||||
|
||||
if (substr ($m->{message}, 0, length ($answer->{csign})) ne $answer->{csign}) {
|
||||
if (substr ($m->{message}, 0, length ($answer->{misc}->{csign})) ne $answer->{misc}->{csign}) {
|
||||
$log->info (sprintf 'Unable to process unknown message: %s', $m->{message});
|
||||
return;
|
||||
}
|
||||
|
||||
my $cmd = substr $m->{message}, length ($answer->{csign});
|
||||
my $cmd = substr $m->{message}, length ($answer->{misc}->{csign});
|
||||
|
||||
if ($cmd eq 'buni') {
|
||||
if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
|
||||
|
||||
@@ -193,7 +193,7 @@ sub Drink {
|
||||
my $r;
|
||||
my $ret = 'Не знаю праздников - вджобываю весь день на шахтах, как проклятая.';
|
||||
my ($dayNum, $monthNum) = (localtime ())[3, 4];
|
||||
my $url = sprintf 'https://kakoysegodnyaprazdnik.ru/baza/%s/%s', $MONTH[$monthNum], $dayNum;
|
||||
my $url = 'https://prazdniki-segodnya.ru/';
|
||||
|
||||
# Those POSIX assholes just forgot to add unix timestamps without TZ offset, so...
|
||||
my ($mday, $mon, $year) = (gmtime ())[3, 4, 5];
|
||||
@@ -254,28 +254,33 @@ sub Drink {
|
||||
if ($r->is_success) {
|
||||
my $p = HTML::TokeParser->new(\$r->body);
|
||||
my @a;
|
||||
my @holyday;
|
||||
my %holiday;
|
||||
|
||||
do {
|
||||
$#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') {
|
||||
push @holyday,'* ' . decode ('UTF-8', $p->get_trimmed_text ('/span'));
|
||||
if ($#{$a[0]} > 2) {
|
||||
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);
|
||||
|
||||
if ($#holyday > 0) {
|
||||
# cut off something weird, definely not a "holyday"
|
||||
$#holyday = $#holyday - 1;
|
||||
}
|
||||
|
||||
if ($#holyday > 0) {
|
||||
$ret = join "\n", @holyday;
|
||||
if (int (keys (%holiday)) > 0) {
|
||||
$ret = join "\n", sort (keys (%holiday));
|
||||
}
|
||||
} else {
|
||||
$log->warn (sprintf '[WARN] Kakoysegodnyaprazdnik 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);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
Reference in New Issue
Block a user