1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-07 16:55:42 -04:00

Fix up some unicode stuff, add in a mini easteregg

This commit is contained in:
Ryan Voots 2017-10-31 21:24:24 -04:00
parent 6e40161b6b
commit e8056da646
3 changed files with 43 additions and 2 deletions

View file

@ -126,3 +126,4 @@ requires 'Math::Calc::Parser';
requires 'ReadonlyX'; requires 'ReadonlyX';
requires 'Const::Fast'; requires 'Const::Fast';
requires 'DateTime::Event::Holiday::US';

View file

@ -6,6 +6,7 @@ use IO::Socket::INET;
use Data::Dumper; use Data::Dumper;
use App::EvalServerAdvanced::Protocol; use App::EvalServerAdvanced::Protocol;
use Encode; use Encode;
use DateTime::Event::Holiday::US;
use strict; use strict;
use utf8; use utf8;
@ -109,10 +110,48 @@ sub command {
$self->{dbh}->do("INSERT INTO evals (input, output) VALUES (?, ?)", {}, $code, $resultstr); $self->{dbh}->do("INSERT INTO evals (input, output) VALUES (?, ?)", {}, $code, $resultstr);
} }
my $holiday=get_holiday();
my %special = (
'Halloween' => {prob => 0.75, chars => ["\x{1F383}", "\x{1F47B}", "\x{1F480}", "\x{1F577}"]},
'Christmas Eve' => {prob => 0.1, chars => ["\x{1F384}", "\x{1F385}"]},
'Christmas' => {prob => 0.5, chars => ["\x{1F384}", "\x{1F385}"]},
);
if ($special{$holiday}) {
if (rand() < $special{$holiday}{prob}) {
my $char = $special{$holiday}{chars}[rand()*@{$special{$holiday}{chars}}];
$resultstr .= " ".$char;
}
}
return( 'handled', $resultstr); return( 'handled', $resultstr);
} }
sub get_holiday {
my $dt = DateTime->now(time_zone=>"PST8PDT")->truncate(to => 'day');
my @known = DateTime::Event::Holiday::US::known();
my $holidays = DateTime::Event::Holiday::US::holidays(@known);
my $mass_set = DateTime::Event::Holiday::US::holidays_as_set(@known); # mass set of all of them
if ($mass_set->contains($dt)) {
# We're a holiday. do shit
my $name = "";
for my $key (@known) {
if ($holidays->{$key}->contains($dt)) {
$name = $key;
last; # don't iterate more.
}
}
return $name;
}
return "";
}
sub do_multieval { sub do_multieval {
my ($self, $types, $code) = @_; my ($self, $types, $code) = @_;

View file

@ -33,8 +33,9 @@ sub unip {
next; next;
} }
my $comb = ""; my $comb = "";
$comb = " " if $x->{name} =~ /^COMBINING /; $comb = " " if $x->{name} =~ /^COMBINING /; # add a space for combining chars
$chr = chr(0x2400 + ord($chr)) if ord($chr) < 0x20; $chr = chr(0x2400 + ord($chr)) if ord($chr) < 0x20; # lower control chars
$chr = "\x{2421}" if ord($chr) == 0x7f; # DEL
push @out, "U+$x->{code} ($utf8): $x->{name} [$comb$chr]"; push @out, "U+$x->{code} ($utf8): $x->{name} [$comb$chr]";
} }