:config system
:base
:help.m

eval addhelp config&config $(c4)[$(c3)setting$(c4)] [$(c3)value$(c4)]&sets a variety of script settings.
alias config {
        ^assign -sctopics
        ^assign -tctopics
        for (@i = 1,getitem(sconf $i),@ i++) {
                ^push sctopics $before(& $getitem(sconf $i))
        }                                               
        for (@i = 1,getitem(tconf $i),@ i++) {          
                ^push tctopics $before(& $getitem(tconf $i))
        }                                               
	if (![$0]) {
		@ sctopics  = sort($sctopics)
		@ tctopics  = sort($tctopics)
		@ stopicnum = numwords($sctopics)
		@ ttopicnum = numwords($tctopics)
	        ^stack push set floating_point_math_var
	        ^set floating_point_math_var on
		@ scollen   = [${stopicnum / 2}]
	        ^stack pop set floating_point_math_var
		if (ismatch(. $scollen)) {
			@ scollen = before(. $scollen)
			@ scollen++
		}
		echo $fparse(format_header core config)
                for (@i = [0],i < scollen,@i++) {
			^assign -tabr1
			^assign -tabr2
			^assign -tsum1
			^assign -tsum2
			^assign -tval1
			^assign -tval2
			for (@j = 1,getitem(sconf $j),@j++) {
			        if (before(& $getitem(sconf $j)) == word($i $sctopics)) {
					@ tabr1 = word($i $sctopics)
					@ tsum1 = before(& $after(& $getitem(sconf $j)))
					@ tval1 = before(& $after(& $after(& $getitem(sconf $j))))
			        }
				if (before(& $getitem(sconf $j)) == word(${i + scollen} $sctopics)) {
					@ tabr2 = word(${i + scollen} $sctopics)
					@ tsum2 = before(& $after(& $getitem(sconf $j)))
					@ tval2 = before(& $after(& $after(& $getitem(sconf $j))))
			        }	
			}                       
			echo $fparse(format_midbar $(c4)[$(c2)$[2]tabr1$(c4)]$(c3) $[19]tsum1 $(c4)[$(c1)$[-3]tolower($($tval1))$(c4)] [$(c2)$[2]tabr2$(c4)]$(c3) $[19]tsum2 $(c4)[$(c1)$[-3]tolower($($tval2))$(c4)])
                }
                for (@i = [0],i < ttopicnum,@i++) {
			^assign -tabr1
			^assign -tsum1
			^assign -tval1
			for (@j = 1,getitem(tconf $j),@j++) {
			        if (before(& $getitem(tconf $j)) == word($i $tctopics)) {
					@ tabr1 = word($i $tctopics)
					@ tsum1 = before(& $after(& $getitem(tconf $j)))
					@ tval1 = before(& $after(& $after(& $getitem(tconf $j))))
			        }
			}                       
			echo $fparse(format_midbar $(c4)[$(c2)$[2]tabr1$(c4)]$(c3) $[19]tsum1 $(c4)[$(c1) $[32]($tval1) $(c4)])
                }
		echo $fparse(format_footer core config)
	}
	{
		if (!match($0 $sctopics) && !match($0 $tctopics)) {
			xecho -b error: invalid config request
		}
		{
			if (match($0 $sctopics)) {
				@ flag = [0]
	                        for (@i = 1,getitem(sconf $i) && flag == [0],@ i++) {
	                                if (before(& $getitem(sconf $i)) == [$0]) {
						@ flag = [1]
	                                        $after(& $after(& $after(& $getitem(sconf $i)))) $1-
	                                }
	                        }
			}
			{
				@ flag = [0]
	                        for (@i = 1,getitem(tconf $i) && flag == [0],@ i++) {
	                                if (before(& $getitem(tconf $i)) == [$0]) {
	                                        @ flag = [1]
						$after(& $after(& $after(& $getitem(tconf $i)))) $1-
	                                }
	                        }
			}				
		}
	}
        ^restub config config.m
}
eval addhelp auto_resume&auto_resume $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggle auto dcc resume.
addconf -s ar&dcc auto resume&auto_resume&auto_resume
addset auto_resume&off
alias auto_resume {
	if ([$0]) {
		if ([$0] == [on]) {
			@ auto_resume = [on]
		}
		{
			@ auto_resume = [off]
		}
	}
	xecho -b dcc auto resume set to $(c4)[$(c2)$auto_resume$(c4)]
	^restub auto_resume config.m
}
eval addhelp beeponpage&beeponpage $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles beeping on ctcp page.
addconf -s bp&beep on page&beeponpage&beeponpage
addset beeponpage&on
alias beeponpage {
        if ([$0]) {
                if ([$0] == [on]) {
                         @ beeponpage = [on]
                }
                {
                         @ beeponpage = [off]
                }
        }        
        xecho -b beeping on ctcp page set to $(c4)[$(c2)$beeponpage$(c4)]
        ^restub beeponpage config.m
}
eval addhelp awaytime&awaytime $(c4)[$(c3)minutes$(c4)]&sets your idle time after which to set away.
addconf -s at&auto away time&awaytime&awaytime
addset awaytime&20
alias awaytime {
        if ([$0]) {
                @ awaytime = [$0]
        }
        xecho -b auto away time set to $(c4)[$(c2)$awaytime$(c4)]$(c3) minute(s).
        ^restub awaytime config.m
}
eval addhelp awaymsg&awaymsg $(c4)[$(c3)away message$(c4)]&sets your default away message.
addconf -t am&away message&awaymsg&awaymsg
addset awaymsg&not here
alias awaymsg {
        if ([$0]) {
                @ awaymsg = [$0-]
        }
        xecho -b default away message set to $(c4)[$(c2)$awaymsg$(c4)]
        ^restub awaymsg config.m
}
eval addhelp backmsg&backmsg $(c4)[$(c3)back message$(c4)]&sets your default back message.
addconf -t bm&back message&backmsg&backmsg
addset backmsg&back now
alias backmsg {
        if ([$0]) {
                @backmsg = [$0-]
        }
        xecho -b default back message set to $(c4)[$(c2)$backmsg$(c4)]
        ^restub backmsg config.m
}
eval addhelp showaway&shoaway $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles public display of aways on and off.
addconf -s sa&show away&showaway&showaway
addset showaway&on
alias showaway {
        if ([$0]) {
                if ([$0] == [on]) {
                         @ showaway = [on]
                }
                {
                         @ showaway = [off]
                }
        }        
        xecho -b public display of away messages is set to $(c4)[$(c2)$showaway$(c4)]
        ^restub showaway config.m
}
eval addhelp autoaway&autoaway $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles autoaway on and off.
addconf -s aa&auto away&autoaway&autoaway
addset autoaway&on
alias autoaway {
        if ([$0]) {
                if ([$0] == [on]) {
                         @ autoaway = [on]
                }
                {
                         @ autoaway = [off]
                }
        }
        xecho -b auto away is set to $(c4)[$(c2)$autoaway$(c4)]
        ^restub autoaway config.m
}
eval addhelp email&email $(c4)[$(c3)address$(c4)]&sets email address.
addconf -t em&email address&email&email
addset email&not@set.yet
alias email {
        if ([$0]) {
                @ email = [$0-]
                xecho -b email address set to $(c4)[$(c2)$email$(c4)]
        }
        {
                xecho -b email address set to $(c4)[$(c2)$email$(c4)]
        }
        ^restub email config.m
}
/* youngdrow's silentchans */
eval addhelp saway&saway $(c4)[$(c3)channels$(c4)]&sets silent away channels.
addconf -t sc&silent away chans&silentchans&saway
addset silentchans&none
alias saway {
        if ([$0]) {
                @ silentchans = [$0-]
                xecho -b silent away channels set to $(c4)[$(c2)$silentchans$(c4)]
        }
        {
                xecho -b silent away channels set to $(c4)[$(c2)$silentchans$(c4)]
        }
        ^restub saway config.m
}
eval addhelp fkeys&f1-6 $(c4)[$(c3)command$(c4)]&binds user defined command to fkeys 1 through 6.
addconf -t f1&function key 1&f1&f1
addset f1&chelp
alias f1 {
        if ([$0]) {
                @f1 = [$0-]
                ^keybind   
        }
        xecho -b function key $(c4)[$(c3)1$(c4)]$(c3) set to $(c4)[$(c2)$f1$(c4)]
        ^restub f1 config.m
}
addconf -t f2&function key 2&f2&f2
addset f2&config
alias f2 {
        if ([$0]) {
                @f2 = [$0-]
                ^keybind   
        }
        xecho -b function key $(c4)[$(c3)2$(c4)]$(c3) set to $(c4)[$(c2)$f2$(c4)]
        ^restub f2 config.m
}
addconf -t f3&function key 3&f3&f3
addset f3&format
alias f3 {
        if ([$0]) {
                @f3 = [$0-]
                ^keybind   
        }
        xecho -b function key $(c4)[$(c3)3$(c4)]$(c3) set to $(c4)[$(c2)$f3$(c4)]
        ^restub f3 config.m
}
addconf -t f4&function key 4&f4&f4
addset f4&theme
alias f4 {
        if ([$0]) {
                @f4 = [$0-]
                ^keybind   
        }
        xecho -b function key $(c4)[$(c3)4$(c4)]$(c3) set to $(c4)[$(c2)$f4$(c4)]
        ^restub f4 config.m
}
addconf -t f5&function key 5&f5&f5
addset f5&dcc
alias f5 {
        if ([$0]) {
                @f5 = [$0-]
                ^keybind   
        }
        xecho -b function key $(c4)[$(c3)5$(c4)]$(c3) set to $(c4)[$(c2)$f5$(c4)]
        ^restub f5 config.m
}
addconf -t f6&function key 6&f6&f6
addset f6&dcc stats
alias f6 {
        if ([$0]) {
                @f6 = [$0-]
                ^keybind   
        }
        xecho -b function key $(c4)[$(c3)6$(c4)]$(c3) set to $(c4)[$(c2)$f6$(c4)]
        ^restub f6 config.m
}
eval addhelp mirck&mirck $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles mirc kick on /clean on and off.
addconf -s mk&kick mirc on clean&mirck&mirck
addset mirck&on
alias mirck {
        if ([$0]) {
                if ([$0] == [on]) {
                        @ mirck = [on]
                }
                {
                        @ mirck = [off]
                }
        }
        xecho -b mIRC kick is set to $(c2)$mirck
        ^restub mirck config.m
}
eval addhelp virck&virck $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles virc kick on /clean on and off.
addconf -s vk&kick virc on clean&virck&virck
addset virck&on
alias virck {
        if ([$0]) {
                if ([$0] == [on]) {
                        @ virck = [on]
                }
                {
                        @ virck = [off]
                }
        }
        xecho -b ViRC kick is set to $(c2)$virck
        ^restub virck config.m
}
eval addhelp pirchk&pirchk $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles pirch kick on /clean on and off.
addconf -s pk&kick pirch on clean&pirchk&pirchk
addset pirchk&on
alias pirchk {
        if ([$0]) {
                if ([$0] == [on]) {
                        @ pirchk = [on]
                }
                {
                        @ pirchk = [off]
                }
        }
        xecho -b PIRCH kick is set to $(c2)$pirchk
        ^restub pirchk config.m
}
eval addhelp xirck&xirck $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles xirc kick on /clean on and off.
addconf -s xk&kick xirc on clean&xirck&xirck
addset xirck&on
alias xirck {
        if ([$0]) {
                if ([$0] == [on]) {   
                        @ xirck = [on]
                }
                {
                        @ xirck = [off]
                }
        }
        xecho -b XiRCON kicks is set to $(c2)$xirck
        ^restub xirck config.m
}
eval addhelp rkreas&rkreas $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles use of random kick reasons on and off.
addconf -s rk&random kick reasons&rkreas&rkreas
addset rkreas&on
alias rkreas {
        if ([$0]) {
                if ([$0] == [on]) {
                        @ rkreas = [on]
                }
                {
                        @ rkreas = [off]
                }
        }
        xecho -b use of random kick reasons set to $(c4)[$(c2)$rkreas$(c4)]
        ^restub rkreas config.m
}
eval addhelp log&log $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles away logging on and off.
addconf -s al&away logging&awaylog&log
addset awaylog&on
alias log {
        if ([$0]) {
                if ([$0] == [off]) {
                        @ awaylog = [off]
                }
                {
                        @ awaylog = [on]
                }
        }
        xecho -b away logging is set to $(c4)[$(c2)$awaylog$(c4)]
        ^restub log config.m
}
eval addhelp page&page $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles away paging on and off.
addconf -s ap&away paging&awaypage&page
addset awaypage&on
alias page {
        if ([$0]) {
                if ([$0] == [off]) {
                        @ awaypage = [off]
                }
                {
                        @ awaypage = [on]
                }
        }
        xecho -b away paging is set to $(c4)[$(c2)$awaypage$(c4)]
        ^restub page config.m
}
eval addhelp topwin&topwin $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles splitting topic windows on and off.
addconf -s tw&split topic window&top&topwin
addset top&on
alias topwin {
        if ([$0]) {
                if ([$0] == [on]) {
                        @ top = [on]
                }
                {
                        @ top = [off]
                }
        }
        xecho -b split topic window set to $(c4)[$(c2)$top$(c4)]
        ^restub topwin config.m
}
eval addhelp autosave&autosave $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles auto loading and saving of script settings. 
addconf -s as&auto save settings&autosave&autosave
addset autosave&on
alias autosave {                                           
        if ([$0]) {
                if ([$0] == [on]) {
                        @ autosave = [on]
                }
                {
                        @ autosave = [off]
                }
        }
        xecho -b auto saving of script and client settings set to $(c4)[$(c2)$autosave$(c4)]
        ^restub autosave config.m
}
eval addhelp autocdcc&autocdcc $(c4)[$(c3)on$(c4)|$(c3)off$(c4)]&toggles auto loading and saving of cdcc settings.
addconf -s ac&auto load/save cdcc&autocdcc&autocdcc
addset autocdcc&on
alias autocdcc {
        if ([$0]) {
                if ([$0] == [on]) {
                        @ autocdcc = [on]
                }
                {
                        @ autocdcc = [off]
                }
        }
        xecho -b auto loading and saving of cdcc settings set to $(c4)[$(c2)$autocdcc$(c4)]
        ^restub autocdcc config.m
}
alias addconf {  
        if (!match($before(& $1) $configlist)) {
                if ([$0] == [-s]) {
                        @ setitem(sconf 0 *)
                        @ setitem(sconf $numitems(sconf) $1-)
                }
                if ([$0] == [-t]) {
                        @ setitem(tconf 0 *)   
                        @ setitem(tconf $numitems(tconf) $1-)
                }
                ^push configlist $before(& $1-)
        }
}
alias remconf {
        @configlist = [$msar(g!$before(& $0)!!$configlist)]
	@configlist = [$msar(g!  ! !$configlist)]
        for (@i = 1,getitem(sconf $i),@ i++) {
                if (before(& $getitem(sconf $i)) == before(& $0-)) {
                        @delitem(sconf $i)
                }
        }
        for (@i = 1,getitem(tconf $i),@ i++) {
                if (before(& $getitem(tconf $i)) == before(& $0-)) {
                        @delitem(tconf $i)
                }                         
        }  
}
alias addset {
	if (!match($before(& $0) $setlist)) {
                @ setitem(set 0 *)
                @ setitem(set $numitems(set) $0-)
                ^push setlist $before(& $0-)
		if ([$($before(& $0))] == []) { 
			@ $before(& $0) = [$after(& $0)]
		}
        }
}
alias remset {
        @setlist = [$msar(g!$before(& $0)!!$setlist)]
        for (@i = 1,getitem(set $i),@ i++) {
                if (before(& $getitem(set $i)) == before(& $0)) {
                        @delitem(set $i)
                }
        }
}
alias loadset {
        for (@i = 1,getitem(set $i),@ i++) {
                @ $before(& $getitem(set $i)) = [$after(& $getitem(set $i))]
        }
}