open publish connection to redis every time
[MQR.git] / scripts / mqr-irc-client.pl
index 58d4374..7873148 100755 (executable)
@@ -22,7 +22,6 @@ 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 { confess @_ } );
 my $sub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { confess @_ } );
 
 $sub->psubscribe( 'channel *', sub {
@@ -56,6 +55,7 @@ $con->reg_cb (
 
                if ( $msg->{command} eq 'PRIVMSG' ) {
                        my $channel = join(' ', 'channel', $msg->{params}->[0], $msg->{prefix});
+                       my $pub = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { confess @_ } );
                        $pub->publish( $channel, $msg->{params}->[1] );
                } elsif ( $msg->{command} eq 'MODE' ) {
                        $con->send_srv( JOIN => $room );