Compare commits
3 Commits
a891c7ed6f
...
f25a4d9ea3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f25a4d9ea3 | ||
|
|
3d6be5ae04 | ||
|
|
4c6a1ea4cd |
2
cpanfile
2
cpanfile
@@ -23,7 +23,7 @@ requires 'Log::Any::Adapter', '==1.710';
|
|||||||
requires 'Log::Any::For::Std', '==0.05';
|
requires 'Log::Any::For::Std', '==0.05';
|
||||||
requires 'Math::Random::Secure', '==0.080001';
|
requires 'Math::Random::Secure', '==0.080001';
|
||||||
requires 'MIME::Base64', '==3.16';
|
requires 'MIME::Base64', '==3.16';
|
||||||
requires 'Mojolicious', '==9.24';
|
requires 'Mojolicious', '==9.26';
|
||||||
requires 'Mojo::IOLoop::Signal', '==0.003';
|
requires 'Mojo::IOLoop::Signal', '==0.003';
|
||||||
# Чтобы заткнуть Mojo::UserAgent::Cached
|
# Чтобы заткнуть Mojo::UserAgent::Cached
|
||||||
requires 'Mojo::Log', '0';
|
requires 'Mojo::Log', '0';
|
||||||
|
|||||||
@@ -98,17 +98,17 @@ my $parse_message = sub {
|
|||||||
$answer->{misc}->{username} = 'user';
|
$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});
|
$log->info (sprintf 'Unable to process unknown message: %s', $m->{message});
|
||||||
return;
|
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});
|
$log->info (sprintf 'Unable to process unknown message: %s', $m->{message});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $cmd = substr $m->{message}, length ($answer->{csign});
|
my $cmd = substr $m->{message}, length ($answer->{misc}->{csign});
|
||||||
|
|
||||||
if ($cmd eq 'buni') {
|
if ($cmd eq 'buni') {
|
||||||
if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
|
if (($m->{plugin} eq 'telegram') && $answer->{misc}->{msg_format}) {
|
||||||
|
|||||||
@@ -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