X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=scripts%2Fmqr-irc-client.pl;h=03f981ae4aea32b7cfbb23bd8c26fc9f3059fb5a;hb=37ca967eebe616179a7331c8256d76ebd817def4;hp=efe43715d6f2b3a15871e61cb84a12b9ab8949cf;hpb=a09f0edff99bc4df61253818b6b1e07b869ea6c8;p=MQR.git diff --git a/scripts/mqr-irc-client.pl b/scripts/mqr-irc-client.pl index efe4371..03f981a 100755 --- a/scripts/mqr-irc-client.pl +++ b/scripts/mqr-irc-client.pl @@ -11,25 +11,27 @@ 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 $subscribe = $ENV{IRC_SUBSCRIBE} || die 'IRC_SUBSCRIBE'; 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}, on_error => sub { warn @_ } ); -my $sub = 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 { confess @_ } ); + +warn "# server:$ENV{IRC_SERVER}:$ENV{IRC_PORT} room:$room nick:$nick subscribe:$subscribe\n"; -$sub->psubscribe( 'channel *', sub { +$sub->psubscribe( "MSG $subscribe", sub { my ( $message, $from ) = @_; - return unless $from !~ m/\Q$nick\E/; # skip our messages - warn "#Q<< $from | $message\n"; - my ( undef, $channel, $user ) = split(/ /,$from,3); - $con->send_msg( 'PRIVMSG', $room => join(' ',$channel, $user, $message) ); + return unless $from !~ m/\Q($nick|$room)\E/; # FIXME: skip our messages + warn "#Q<< ",dump( $from, $message ); + my ( undef, $gw, $user ) = split(/ /,$from,3); + $user =~ s{^.+/}{}; + $con->send_msg( 'PRIVMSG', $room => "<$user> $message" ); }); $con->reg_cb ( @@ -54,8 +56,11 @@ $con->reg_cb ( ); if ( $msg->{command} eq 'PRIVMSG' ) { - my $channel = join(' ', 'channel', $msg->{params}->[0], $msg->{prefix}); - $pub->publish( $channel, $msg->{params}->[1] ); + 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, $body ); } elsif ( $msg->{command} eq 'MODE' ) { $con->send_srv( JOIN => $room ); }