#!/usr/bin/perl -I/usr/depot/lib/perl5
#
# requires a psyc server to do anything useful -
# will tell a UNI on that server that this unix
# user is here or away now. on the receiver's side
# it appears as a notify-message or buddy-list change
# according to the interface the receiver uses.
#
# currently this will not be displayed without proper
# authentication, it will instead trigger a protocol
# breach warning. so be careful with this, or put
# proper _identification into here.. TODO

#use Net::PSYC qw( Event=IO::Select ); # no eventing!?
use Net::PSYC;

use Getopt::Std;
getopt('tbimnd');

$binder = $opt_b || 'psyc://:0d/';      # get yourself any udp port

# TODO: this needs to be updated to http://about.psyc.eu/presence !!
$mc = "_notice_friend_present";
$mc = "_notice_friend_absent" if $opt_a;
$mc = $opt_m if $opt_m;

$nick = $opt_n
     || $ENV{'PSYCNICK'}
     || $ENV{'NICK'}		# this one should work with any chat system
     || $ENV{'IRCNICK'}
     || $ENV{'USER'}
     || 'unixer';

#bind_uniform( $binder ); 
# we dont need no port .. do we?

unless (@ARGV) {
	print <<X;

Hello, $nick!

usage: $0 [-a] [-n <nick>] [-b <uniform>] [<UNI>]+

sends a presence notification to all given UNIs
message defaults to "present", will send "absent" when given the -a flag.

it is correct that psyced doesn't display the "absent" message in most cases,
it will use the information internally, though
X
	exit;
}

# a firework of messages leaving this place
foreach (@ARGV) {
	$rc = sendmsg( $_, $mc, $opt_d, { _nick => $nick } );
	print STDER "sendmsg to $_: $rc" if $rc;
}

sleep 4;
exit;

