massive routing cleanup
[MQR.git] / scripts / mqr-irc-client.pl
index 7873148..5e491be 100755 (executable)
@@ -15,8 +15,7 @@ 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 $subscribe  = $ENV{IRC_SUBSCRIBE} || die 'IRC_SUBSCRIBE';
 
 my $c = AnyEvent->condvar;
 my $stdout = AnyEvent::Handle->new (fh => \*STDOUT);
@@ -24,9 +23,11 @@ my $con = new AnyEvent::IRC::Client;
 
 my $sub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { confess @_ } );
 
-$sub->psubscribe( 'channel *', sub {
+warn "# server:$ENV{IRC_SERVER}:$ENV{IRC_PORT} room:$room nick:$nick subscribe:$subscribe\n";
+
+$sub->psubscribe( "MSG $subscribe", sub {
        my ( $message, $from ) = @_;
-       return unless $from !~ m/\Q$nick\E/; # skip our messages
+       return unless $from !~ m/\Q($nick|$room)\E/; # FIXME: skip our messages
        warn "#Q<< ",dump( $from, $message );
        my ( undef, $channel, $user ) = split(/ /,$from,3);
        $con->send_msg( 'PRIVMSG', $room => join(' ',$channel, $user, $message) );
@@ -54,9 +55,11 @@ $con->reg_cb (
       );
 
                if ( $msg->{command} eq 'PRIVMSG' ) {
-                       my $channel = join(' ', 'channel', $msg->{params}->[0], $msg->{prefix});
+                       my ( $to, $body ) = @{ $msg->{params} };
+                       my $channel = join(' ', 'MSG', "$nick/$to", $msg->{prefix});
+                       warn "#Q>> $channel | $body\n";
                        my $pub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { confess @_ } );
-                       $pub->publish( $channel, $msg->{params}->[1] );
+                       $pub->publish( $channel, $body );
                } elsif ( $msg->{command} eq 'MODE' ) {
                        $con->send_srv( JOIN => $room );
                }