:action fix
:module
:misc.m
# all this to get nice lookin query actions, feel free to use
alias join {
        @ setitem(winchans $numitems(winchans) $channame($0) $winnum())
        //join $channame($0) $1-
}
alias j {
        join $0-
}
alias part {
        ^assign -chan
        if ([$0]) {
                @chan = channame($0)
        }
        {
                if ([$T]) {
                        @chan = T
                }
        }
        if ([$chan]) {
                for (@i = 0,getitem(winchans $i),@i++) {
                        if (word(0 $getitem(winchans $i)) == [$chan] && word(1 $getitem(winchans $i)) == [$winnum()]) {
                                @ delitem(winchans $i)
                        }
                }
                //part $chan
        }
}

^on ^action "*" {
        if ([$1]==N) {
                xecho -w $querywin($0) $fparse(format_action_other $time() $0 $userhost() $N $2-)
        } 
	{
		^assign -wn
		fe ($winrefs()) wn {
			if (winchan($wn) == [$1] && winserv($wn) == lastserver()) {
				if (match($N $2-)) {
			                xecho -w $wn $fparse(format_action_ar $time() $0 $userhost() $1 $2-)
				}
				{
					xecho -w $wn $fparse(format_action $time() $0 $userhost() $1 $2-)
				}
		        } 
		}
                for (@i = 0,getitem(winchans $i),@i++) {
                        if (word(0 $getitem(winchans $i)) == [$1] && chanwin($1) == [-1] && winserv($word(1 $getitem(winchans $i))) == [$lastserver()]) {
		                if (match($N $2-)) {
					xecho -w $word(1 $getitem(winchans $i)) $fparse(format_action_other_ar $time() $0 $userhost() $1 $2-)
				}
				{
					xecho -w $word(1 $getitem(winchans $i)) $fparse(format_action_other $time() $0 $userhost() $1 $2-)
				}
			}
	        }
	}
}
alias me {
	if (Q) {
		^ctcp $Q ACTION $0-
		xecho -c $fparse(format_send_action_other $time() $N $Q $0-)
	}
	{
		//me $0-
	}
	^restub me action.m
}