:scan formatting
:module
:

alias fix.scnick {
        if ([$[1]0] == [@]) {
                @ nick = right(${strlen($0) - 1} $0)
                @ function_return = [$(sc1)@$(sc3)$[9]nick]
        }
        {
	        if ([$[1]0] == [+]) {
        	        @ nick = right(${strlen($0) - 1} $0)
			@ function_return = [$(sc2)+$(sc3)$[9]nick]
	        }
		{
	                @ function_return = [ $(sc3)$[9]0]
        	}
	}
}
alias scan {
	if ([$0]) {
		@ scanchan = [$0]
	}
	{	
		@ scanchan = T
	}
	if (match($scanchan $mychannels())) { 
		if (channel($scanchan)) {
			^hook showscan $scanchan $strip(.* $channel($scanchan))
		}	
		{
			^hook showscan $scanchan $gotchan[$encode($tolower($scanchan))]
		}
	}	
	{
		xecho -b scan: You are not on $scanchan
	}
        ^restub scan scan.m
}
alias sc {
	^scan $* 
        ^restub sc scan.m
}
^on ^raw_irc "% 366 *" {
	^hook showscan $3 $sort($gotchan[$encode($tolower($3))])
}
^on ^hook "showscan *" {
	^local nicks $2-
	^local chan $1
        ^local scan
	^local vnum
	^local onum
	^local nnum
	^local tnum
        ^push scan $pattern(@% $nicks)
	@ onum = numwords($scan)
        ^push scan $pattern(+% $nicks)
	@ vnum = [${numwords($scan) - onum}]
        ^push scan $filter(+% $filter(@% $nicks))
	@ nnum = [${numwords($scan) - onum - vnum}]
	@ tnum = numwords($scan)
	if (fparse(format_scan_header1) != [format_scan_header1]) { xecho -w $chanwin($chan) $fparse(format_scan_header1 $chan $onum $vnum $nnum $tnum) }
        if (fparse(format_scan_header2) != [format_scan_header2]) { xecho -w $chanwin($chan) $fparse(format_scan_header2 $chan $onum $vnum $nnum $tnum) }
        while (numwords($scan) > 0) {
		xecho -w $chanwin($chan) $fparse(format_scan_users $shift(scan) $shift(scan) $shift(scan) $shift(scan) $shift(scan))
	}
	if (fparse(format_scan_footer1) != [format_scan_footer1]) { xecho -w $chanwin($chan) $fparse(format_scan_footer1 $chan $onum $vnum $nnum $tnum) }
	if (fparse(format_scan_footer2) != [format_scan_footer2]) { xecho -w $chanwin($chan) $fparse(format_scan_footer2 $chan $onum $vnum $nnum $tnum) }
}
# from osiris, i like it
^on ^353 * {
	^push gotchan[$encode($tolower($2))] $3-
}
^on #-channel_synch 2 * { ^assign -gotchan[$encode($tolower($0))] }
