#!/pro/bin/perl

use 5.14.1;
use warnings;

my $VERSION = "1.3";	# 2013-01-31

use charnames qw(:full);
use Xchat     qw(:all);
use Encode    qw(encode);

register ("Prog FM", $VERSION, "Be happy with the music being played on prog.fm");

my $notes = "\N{BEAMED SIXTEENTH NOTES}\N{BEAMED EIGHTH NOTES}".
	    "\N{EIGHTH NOTE}\N{QUARTER NOTE}";

# /np irrwisch
# /np camel auralmoon
# ->
#       ♬♫♪♩ #nowplaying on #prog.fm ♬♫♪♩ #camel++ ☺ 👍 ♬♫♪♩
# <Tux> ♬♫♪♩ #nowplaying on #prog.fm ♬♫♪♩ #camel++ ☺ 👍 ♬♫♪♩
hook_command ("NP", sub {
    my $nick    = Xchat::get_info ("nick");
#   my $channel = Xchat::get_info ("channel");
#   my $net     = Xchat::get_info ("network");
    my ($cmd, @arg) = @{$_[0]};
    my $who = (shift @arg) // "performer";
    my $whr = (shift @arg) // "ProgFM";
    my $msg = encode ("utf-8", join " " =>
	$notes,
	"#nowplaying",
	"on #${whr}",
	$notes,
	"#${who}++",
	"\N{WHITE SMILING FACE}",
	"\N{THUMBS UP SIGN}",
	$notes, @arg,
	);
    # Local to text area, not sent to server
    # Xchat::print ($msg);
    # Send to server, as if I typed it
    #Xchat::emit_print ("Channel Message", $nick, $msg, "", "");
    # Actually say it
    my $l = length $msg;
    if ($l > 140) {
	Xchat::print ("The message length ($l) is over 140 characters");
	}
    else {
	Xchat::command ("say $msg");
	}
    return EAT_NONE; #EAT_NONE;
    });
