diff --git a/cpanfile b/cpanfile index ac0ef3b..f8b08a4 100644 --- a/cpanfile +++ b/cpanfile @@ -126,3 +126,4 @@ requires 'Math::Calc::Parser'; requires 'ReadonlyX'; requires 'Const::Fast'; +requires 'DateTime::Event::Holiday::US'; diff --git a/plugins/supereval.pm b/plugins/supereval.pm index d89537b..b17cb97 100644 --- a/plugins/supereval.pm +++ b/plugins/supereval.pm @@ -6,6 +6,7 @@ use IO::Socket::INET; use Data::Dumper; use App::EvalServerAdvanced::Protocol; use Encode; +use DateTime::Event::Holiday::US; use strict; use utf8; @@ -109,10 +110,48 @@ sub command { $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); } +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 { my ($self, $types, $code) = @_; diff --git a/plugins/unicode.pm b/plugins/unicode.pm index 21cdec8..037d0f3 100644 --- a/plugins/unicode.pm +++ b/plugins/unicode.pm @@ -33,8 +33,9 @@ sub unip { next; } my $comb = ""; - $comb = " " if $x->{name} =~ /^COMBINING /; - $chr = chr(0x2400 + ord($chr)) if ord($chr) < 0x20; + $comb = " " if $x->{name} =~ /^COMBINING /; # add a space for combining chars + $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]"; }