From 67d4383081ddc4173765fccb4de0a532be3651cf Mon Sep 17 00:00:00 2001 From: Al Beano Date: Mon, 4 Jul 2016 22:28:22 +0100 Subject: [PATCH] fix crashes relating to unicode characters --- MarkovBot.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MarkovBot.pl b/MarkovBot.pl index 7e2df21..a8e7cc4 100644 --- a/MarkovBot.pl +++ b/MarkovBot.pl @@ -15,6 +15,7 @@ use MarkovBot::Ignore; use MarkovBot::Commands; use MarkovBot::MarkovChain; use MarkovBot::Redis; +use Encode qw(encode decode); sub said { my $self = shift; @@ -30,7 +31,7 @@ sub said { # Intercept commands if ($msg->{body} =~ m/^$command_char.+/) { - my $command = $msg->{body}; + my $command = encode("UTF-8", $msg->{body}); my @command = split(" ", $command); my $bare = $command[0]; $bare =~ s/^$command_char//; @@ -39,7 +40,7 @@ sub said { if (defined $subs{$bare}) { my $ret = $subs{$bare}->(\@command); - $self->say( channel => config("irc_channel"), body => $ret ) unless $ret eq "___null___"; + $self->say( channel => config("irc_channel"), body => decode("UTF-8", $ret) ) unless $ret eq "___null___"; } return;