From 2a85bdefca654241cc16939890236300516cfb0b Mon Sep 17 00:00:00 2001 From: William Heimbigner Date: Sat, 26 Dec 2015 20:23:48 -0700 Subject: Create a fifo, relay it into masterchan (awesome for git web hook, and for making dwfreed wonder how the bot is talking) --- lib/ASM/Fifo.pm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/ASM/Fifo.pm (limited to 'lib') diff --git a/lib/ASM/Fifo.pm b/lib/ASM/Fifo.pm new file mode 100644 index 0000000..1a480f8 --- /dev/null +++ b/lib/ASM/Fifo.pm @@ -0,0 +1,33 @@ +package ASM::Fifo; + +use warnings; +use strict; +use POSIX qw(mkfifo); +use Fcntl; + +sub new +{ + my $module = shift; + my @args = @_; + my $self = { + "irc" => $args[0], + "conn" => $args[1] + }; + mkfifo("fifo", 0777); + sysopen( my $fifo, "fifo", O_NONBLOCK ); + $self->{fifo} = $fifo; + bless($self); + $self->{irc}->addfh( $self->{fifo}, sub { $self->process(@_); }, 'r' ); + return $self; +} + +sub process +{ + my ($self, $fifo) = @_; + my $line = readline($fifo); + return unless defined($line); + chomp $line; + $self->{conn}->privmsg($::settings->{masterchan}, $line); +} + +1; -- cgit v1.2.3