~mplscorwin/git-udp-syndicate

6d584a5efdaf08d44cbc53cbb482885cbe1929c4 — Corwin Brust 4 months ago 7c9c91e master
add fifo writer to irc gateway
1 files changed, 26 insertions(+), 0 deletions(-)

M udp-to-irc.pl
M udp-to-irc.pl => udp-to-irc.pl +26 -0
@@ 44,6 44,7 @@ no warnings q[experimental];
use Future::AsyncAwait;

use IO::Async::Loop;
use IO::Async::Stream;
use IO::Async::Socket;
use Net::Async::WebSocket::Client;
use Net::Async::IRC;


@@ 205,6 206,31 @@ if ($IRC_ENABLED) {
    $loop->add( $irc );
}


my $fifo_file = q(/petroglyph/udp2irc/gliphy.fifo);
open my $fifo,  '+<', $fifo_file
    or die qq(cannot open $fifo_file; $! - $?);

my $pipe = IO::Async::Stream->new(
   read_handle  => $fifo,
   on_read => sub {
      my ( $self, $buffref, $eof ) = @_;

      while( $$buffref =~ s/^(.*)\n// ) {
	my ( $room, $text ) = split /\s+/, $1, 2;
	next unless $room and $text;

	$irc->do_PRIVMSG(
	    target => $room,
	    text => $text,
	);
      }

      return 0;
   }
);
$loop->add( $pipe );

## setup the UDP listener
my $socket = IO::Async::Socket->new(
   on_recv => sub {