#!/usr/bin/perl 
#Author: Nathan Handler
#Last Modified: 2010-11-21
use strict; 
use File::Copy;
use File::Touch;

#Requires fnotify.pl: http://www.leemhuis.info/files/fnotify/fnotify
my $name = '/home/nhandler/.irssi/fnotify';
my $name2 = '/home/nhandler/.irssi/fnotify.processing';
while(1) {
	touch("$name");
	move("$name", "$name2");
	open(FILE, "<$name2") || die "Failed to Open $name2: $!\n";
	my @lines = <FILE>;
	close(FILE);
	foreach my $line (@lines) {
		$line =~ s/[&]//g;
		my($heading,$message)=split(/ /, $line, 2);
		system("/usr/bin/notify-send -i notification-message-im -- \"$heading\" \"$message\"");
		if(`screen -list | grep '(Attached)'`) {
			$message=~s/^.*>//;
			if($message=~m/!ops/i) {
				$message="!ops";	#Don't read all the names in an !ops call
			}
			system("echo \"$message\" | /usr/bin/festival --tts");
		}
		else { 
			system("/usr/bin/prowl -application=Irssi -event=\"$heading\" -notification=\"$message\" -priority=0 -apikey=PROWLAPIKEYGOESHERE");
		}
	}

	sleep 1;
}

