we don't need to touch encoding for AnyEvent::IRC
[MQR.git] / scripts / mqr-xmpp-client.pl
index d0a7e67..ba191c2 100755 (executable)
@@ -9,6 +9,7 @@ use AnyEvent::XMPP::Ext::Version;
 use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
 use AnyEvent::Redis;
 use Data::Dump qw(dump);
+use Encode;
 
 binmode STDOUT, ":utf8";
 
@@ -28,15 +29,16 @@ $cl->set_presence(undef, 'I\'m a talking bot.', 1);
 $cl->add_account ($jid, $pw);
 warn "connecting to $jid...\n";
 
-my $pub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT} );
-my $sub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT} );
+my $pub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { warn @_ } );
+my $sub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { warn @_ } );
 
 our $contacts;
 
 $sub->psubscribe( 'channel *', sub {
        my ( $message, $from ) = @_;
        return unless $from !~ m/\Q$jid\E/; # skip our messages
-       warn "#Q<< $from [$jid] | $message\n";
+       Encode::_utf8_on($message);
+       warn "#Q<< ", dump( $from, $message );
        my ( undef, $channel, $user ) = split(/ /,$from,3);
 warn "# contacts ",dump($contacts);
        foreach my $contact ( keys %$contacts ) {
@@ -63,8 +65,9 @@ $cl->reg_cb (
 warn "# contacts ",dump($contacts);
 
                my $channel = join(' ', 'channel', $msg->from);
+               Encode::_utf8_off($body);
                $pub->publish( $channel, $body );
-               warn "#X<< $channel | $body\n";
+               warn "#X<< ",dump($channel, $body);
 
 #              my $repl = $msg->make_reply;
 #              $repl->add_body( $response );