#!/usr/bin/perl

# NPscript v.2.00 for XChat
#
# By Apollon Koutlides ( apollon@peftoulas.org )
#
# Latest version can be usually found at http://gnutrout.peftoulas.org
# 

# Usage: /np text
#
# Add excluded channels below:
#
#$channels{"#linuxhelp"}=1;
$channels{"#ad&d"}=1;
$channels{"#blip"}=1;

# DO NOT MODIFY ANYTHING BELOW THIS LINE

$vnum ="2.51";
$vdate="Mar 31, 2004";
IRC::add_command_handler("np", "np");

IRC::print "NPscript v$vnum ($vdate) for XChat\nBy GnuLxUsr ( apollon\@planewalk.net )\n";
IRC::print "Usage: /np [text]          Displays [text] for current server & nick\n";
IRC::print "           *** If parameter is omitted and you have xmms-infopipe\n";
IRC::print "               installed and enabled in xmms, the currently\n";
IRC::print "               played file title will be retrieved and sent.\n";
IRC::print "\n";


sub np
{
	$text = join(" ", @_);
	if ($text =~ /^$/) {
		open INFILE,"/tmp/xmms-info";
		while (<INFILE>) {
			if ($_ =~ /^Title/) {
				$text = $_;
			}
		}
		#$text = `cat /tmp/xmms-info | grep Title`;
		chomp $text;
		$text =~ s/^Title: //;
		$text =~ s/\.wav$//;
		$text =~ s/\.ogg$//;
		$text =~ s/\.mp3$//;
		$text =~ s/-[0-9][0-9]//;
		$text =~ s/- [0-9][0-9] //;
		$text =~ s/^[0-9][0-9]\.//;
		$text =~ s/^\s*//;
		$text =~ s/\s*$//;
	}
	@channels=IRC::channel_list();
	$curni=IRC::get_info(1);
	$curse=IRC::get_info(3);
	while ( $channel = shift(@channels) ) {
		$server=shift(@channels);
		$nick=shift(@channels);
		#IRC::print "> $nick\@$channel\:$server";
		if ( $channel =~ /#.*/ && $server eq $curse && $nick eq $curni ) {
			IRC::command "/ctcp $channel ACTION np $text" unless $channels{$channel} == 1;
			#IRC::print "/ctcp $channel ACTION np $text" unless $channels{$channel} == 1;
		}
	}
	return 1;
}
