# quick script to print notifys to the current window
# probably buggy and currently looks quite ugly.  Requested by P38

# Changes
# 0.6a: Removed / from Irssi::command, not required.

use strict;
use Irssi 20030709; # irssi 0.8.6.CVS (20030709 2336)
use Irssi::Irc;

use vars qw($VERSION %IRSSI);
$VERSION = "0.6a";
%IRSSI = (
	authors		=> "David O\'Rourke",
	contact		=> "script\@no.email.yet",
	name		=> "notifycurrent",
	description	=> "Print a notice in the current window when someone on your notify list is online",
	licence		=> "GPL General Public Licence"
);

sub notify_joined {
	my ($server, $nick, $user, $address, $realname, $awaymsg) = @_;
	my $network = $server->{tag};
	my $where = Irssi::settings_get_str('notify_window');
	my $window;

	return if (!$server);
	# where are we going to print this?
	return if (!$where);
	if ("$where" eq "active") {
		$window = Irssi::active_win();
	} else {
		$window = $server->channel_find($where);
	}
	
	if (!$awaymsg) {
		if ("$where" eq "active") {
			$window->print("$nick \[$user\@$address\] \[$realname\] has joined $network", MSGLEVEL_NOTICES);
			return if Irssi::settings_get_bool('notify_window_only') == 0;
			Irssi::signal_stop();
		} else {
			Irssi::command("msg -$network $where Notify: $nick \[$user\@$address\] \[$realname\] has joined $network");
			return if Irssi::settings_get_bool('notify_window_only') == 0;
			Irssi::signal_stop();
		}
	} else {
		if ("$where" eq "active") {
			$window->print("$nick \[$user\@$address\] \[$realname\] \[$awaymsg\] has joined $network", MSGLEVEL_NOTICES);
			return if Irssi::settings_get_bool('notify_window_only') == 0;
			Irssi::signal_stop();
		} else {
			Irssi::command("msg -$network $where Notify: $nick \[$user\@$address\] \[$realname\] \[$awaymsg\] has joined $network");
			return if Irssi::settings_get_bool('notify_window_only') == 0;
			Irssi::signal_stop();
		}
	}
}

Irssi::settings_add_str('notify', 'notify_window', 'active');
Irssi::settings_add_bool('notify', 'notify_window_only' => 1);
Irssi::signal_add_first('notifylist joined', 'notify_joined');

