confess on all redis errors
[MQR.git] / scripts / mqr-irc-client.pl
index 22cea7d..58d4374 100755 (executable)
@@ -11,21 +11,24 @@ use AnyEvent::IRC::Client;
 use AnyEvent::IRC::Util qw/mk_msg parse_irc_msg encode_ctcp/;
 use AnyEvent::Redis;
 use Data::Dump qw(dump);
+use Carp qw(confess);
 
 my $nick = $ENV{IRC_NICK} || die "IRC_NICK";
 my $room = $ENV{IRC_ROOM} || die "IRC_ROOM";
 
+warn "# $ENV{IRC_SERVER}:$ENV{IRC_PORT} $room $nick\n";
+
 my $c = AnyEvent->condvar;
 my $stdout = AnyEvent::Handle->new (fh => \*STDOUT);
 my $con = new AnyEvent::IRC::Client;
 
-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 { confess @_ } );
+my $sub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { confess @_ } );
 
 $sub->psubscribe( 'channel *', sub {
        my ( $message, $from ) = @_;
        return unless $from !~ m/\Q$nick\E/; # skip our messages
-       warn "#Q<< $from | $message\n";
+       warn "#Q<< ",dump( $from, $message );
        my ( undef, $channel, $user ) = split(/ /,$from,3);
        $con->send_msg( 'PRIVMSG', $room => join(' ',$channel, $user, $message) );
 });