summaryrefslogtreecommitdiff
path: root/lib/Multi
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-04-29 10:11:46 +0200
committerYorhel <git@yorhel.nl>2015-04-29 10:11:46 +0200
commitfdda38d11baba8a24d97d4c19b75eee158666bfa (patch)
tree92362205b043a5fbc01c5892be8b28d2062a85bf /lib/Multi
parentfcd4056671eab67b8a18416e743bb3abe092a626 (diff)
Multi::(API:IRC): Fix some unicode handling issues
I forgot that AnyEvent::Handle works with bytes rather than unicode strings, even though that is kind of obvious. I expected that AnyEvent::IRC would automatically handle the conversion between byte strings and Unicode strings, but it doesn't, so that has to be done manually.
Diffstat (limited to 'lib/Multi')
-rw-r--r--lib/Multi/API.pm4
-rw-r--r--lib/Multi/IRC.pm10
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/Multi/API.pm b/lib/Multi/API.pm
index a5a4b3f5..36b4be5c 100644
--- a/lib/Multi/API.pm
+++ b/lib/Multi/API.pm
@@ -12,7 +12,7 @@ use AnyEvent::Socket;
use AnyEvent::Handle;
use POE::Filter::VNDBAPI 'encode_filters';
use Digest::SHA 'sha256';
-use Encode 'encode_utf8';
+use Encode 'encode_utf8', 'decode_utf8';
use Crypt::ScryptKDF 'scrypt_raw';;
use VNDBUtil 'normalize_query', 'norm_ip';
use JSON::XS;
@@ -153,7 +153,7 @@ sub cmd_read {
(my $msg = $_[1]) =~ s/[\r\n]*/ /;
$msg =~ s/^[\s\r\n\t]+//;
$msg =~ s/[\s\r\n\t]+$//;
- writelog $c, "< $msg" if $cmd && $cmd ne 'login';
+ writelog $c, decode_utf8 "< $msg" if $cmd && $cmd ne 'login';
# Stats for the current cmd
$c->{sqlt} = $c->{sqlq} = 0;
diff --git a/lib/Multi/IRC.pm b/lib/Multi/IRC.pm
index cf4bf5aa..ad5a456d 100644
--- a/lib/Multi/IRC.pm
+++ b/lib/Multi/IRC.pm
@@ -13,6 +13,7 @@ use AnyEvent::IRC::Util 'prefix_nick';
use VNDBUtil 'normalize_query';
use TUWF::Misc 'uri_escape';
use POSIX 'strftime';
+use Encode 'decode_utf8', 'encode_utf8';
# long subquery used in several places
@@ -93,7 +94,7 @@ sub send_quote {
my $chan = shift;
pg_cmd 'SELECT quote FROM quotes ORDER BY random() LIMIT 1', undef, sub {
return if pg_expect $_[0], 1 or !$_[0]->nRows;
- $irc->send_msg(PRIVMSG => $chan, $_[0]->value(0,0));
+ $irc->send_msg(PRIVMSG => $chan, encode_utf8 $_[0]->value(0,0));
};
}
@@ -145,7 +146,7 @@ sub set_logger {
my $l = sub {
my($chan, $msg, @arg) = @_;
return if !grep $chan eq $_, @{$O{channels}};
- open my $F, '>>:utf8', "$VNDB::M{log_dir}/$chan" or die $!;
+ open my $F, '>>', "$VNDB::M{log_dir}/$chan" or die $!;
print $F strftime('%Y-%m-%d %H:%M:%S', localtime).' '.sprintf($msg, @arg)."\n";
};
@@ -259,7 +260,7 @@ sub formatid {
push @msg, $c."@ $NORMAL$LIGHT_GREY$VNDB::S{url}/$id$NORMAL";
# now post it
- $irc->send_msg(PRIVMSG => $dest, join ' ', @msg);
+ $irc->send_msg(PRIVMSG => $dest, encode_utf8 join ' ', @msg);
}
}
@@ -475,7 +476,7 @@ eval => [ 1, 1, sub {
if(@l > 5 || length(join ' ', @l) > 400) {
$irc->send_msg(PRIVMSG => $_[1], 'Output too large, refusing to spam chat (and too lazy to use a pastebin).');
} else {
- $irc->send_msg(PRIVMSG => $_[1], "eval: $_") for @l;
+ $irc->send_msg(PRIVMSG => $_[1], encode_utf8("eval: ".$_)) for @l;
}
}],
@@ -488,6 +489,7 @@ die => [ 1, 1, sub {
# Returns 1 if there was a valid command (or something that looked like it)
sub command {
my($nick, $chan, $msg) = @_;
+ $msg = decode_utf8($msg);
my $me = $irc->nick();
my $addressed = !$irc->is_channel_name($chan) || $msg =~ s/^\s*\Q$me\E[:,;.!?~]?\s*//;