/* original idea for getnick by MadHack (keepnick) */
/* original code by fudd */
/* improvements by nutbar patched in 02/10/98 (what a stud) */

alias getnick if ([$0] && [$0] != N) {
    switch ($0) {
	(-) {pecho Getnick is now -$(hwht)inactive$(cl)-;@ p.getnick = p.nick = []}
	(*) {
	    @ p.nick = [$0]
	    @ p.getnick = [1]
	    pecho Getnick attempting to regain nick $fix.c1($p.nick)
	    if (!checkhost($p.nick)) {_get_nick}
	}
    }
}{
    if ([$0] == N) {
	pecho $(cyn)ERROR$(cl) - Your current nick is already $fix.c1($0)
    }{
	pecho Getnick is currently $gn_status() $fix.c1($p.nick)
	pecho Usage: /getnick <nick> | /getnick -
    }
}

alias gn_status {@ function_return = p.getnick ? [-$(hwht)active$(cl)-] : [-$(hwht)inactive$(cl)-]}

#on ^433 '$p.nick *' if (p.getnick) {^timer -ref getnick 30 nick $p.nick}
on ^401 '% $p.nick *' if (p.getnick) {_get_nick}
on #-channel_signoff 613 '% $p.nick *' if (p.getnick) {_get_nick}
on #-nickname 613 '$p.nick %' if (p.getnick) {_get_nick}
on #-notify_signoff 613 '$p.nick %' if (p.getnick && [$1] == p.nick) {_get_nick}
on #-timer 613 * if (p.getnick) {
    if (!S) {@ p.getnick = p.nick = [];pecho Getnick has been disabled}
    if (!checkhost($p.nick)) {_get_nick}
}

alias _get_nick if (S) {
    pecho Regaining nick $fix.c1($p.nick)
    nick $p.nick
    @ p.getnick = p.nick = []
}
