eval echo $colorize(`0`b//`6Mad's colirc Script`0`b//)

# stuff
usecolor -bblack -bwhite -blue -bgreen -brown -white
umode +is

# general sets
set novice off
set help_path .irchelp
set history 30
set lastlog 1000
set lastlog_level all dcc
set -input_prompt
set indent on
set flood_warning off
set client_information MadIRC 1.0
# signoff msg if you don't provide one
@ signmsg = [brainless logoff]
# set to 0 if you don't want to autoget dccs
@ autoget = 1

# aliases
alias l leave *
alias op mode * +o $0
alias deop mode * -o $0
alias k kick * $0 $1-
alias ban mode * +b $0
alias unban mode * -b $0
alias j if ([#]==[$[1]0]) {//join $0-} {//join #$0-}
alias m msg
alias sc names *
alias r load .script
alias sc names *
alias listb mode * +b
alias lj leave $C;timer 3 join $C
alias nick quote nick
alias quit signoff $0-

# people stuff
alias friend @friends = [$friends $0]
alias enemy @enemies = [$enemies $0]
alias aop @aops = [$aops $0]

# make a file called .folx and stick your friends/enemies/aops in it, then
# uncomment the following line...here's a sample of what's in it
# load .folx
friend madhacker
enemy billgates
aop *!*@clue.oz.net

# key bindings
bind meta1-[ meta2
bind meta1-O meta2
bind meta2-A backward_history
bind meta2-B forward_history
bind meta2-C forward_character
bind meta2-D backward_character
bind ^B self_insert
bind ^_ self_insert
bind ^V self_insert
bind ^X switch_channels
bind ^I parse_command ^getmsg 1 $msglist 

# status bar
set clock on
set clock_24hour off
set status_clock %T
set status_format [%T] %@%N%#%C%+ %>%U

# cool shit
# auto rejoin
on ^kick "*" {
	echo $colorize(`4*** `6`b$0 `6has been kicked off $2 by `b$1`6 \(`b$3-`6\))
	if ([$0] == [$N]) {
		wait -CMD # 
		join $2
	}
}
on ^send_msg * {
	echo $colorize(`b//`2`b$0`7`b//`7 $1-)
	^addmsg $0 $msglist
}
on ^msg * {
	echo $colorize(`b\\\\$0\\\\`7 $1-)
	^addmsg $0 $msglist
}
on ^send_action * echo $colorize(* `2`b$N`7 $1-)
on ^send_public * echo $colorize(`b<`2`b$N`7`b>`7 $1-)
on ^mode * echo $colorize(`4*** `6mode "`b$2-`6" on $1 by `b$0)
on ^leave * echo $colorize(`4*** `6`b$0 `6left $1)
on ^signoff * echo $colorize(`4*** `6signoff: `b$0 `6\(`b$1-`6\))
on ^nickname * echo $colorize(`4*** `6`b$0`6 is now `b$1)
on ^topic * echo $colorize(`4*** `6topic "`b$2-`6" on $1 by `b$0)
# topic
on ^332 * echo $colorize(`4*** `6topic for $1 "`b$2-`6")
on ^333 * echo $colorize(`4*** `6topic by `b$2`6\($stime($3)\)) 
on ^join * echo $colorize(`4*** `6`b$0 `6joined $1)
# who
on ^raw_irc "% 352 *" echo $colorize(`4*** `6`b$4: `6$7@$5 \($10-\))
on ^signoff * echo $colorize(`4*** `6signoff: `b$0`6\(`b$1-`6\))
on ^server_notice *

# color follow nick
on #^nickname 100 * {
	@ color1 = colorof($0)
	@ color2 = mid(1 1 $color1)
	@ color3 = [$color2$mid(3 1 $color1)
	color $1 $color3
}

# names
on ^353 * {
	@printme = [`6`b$2`6:]
	@folx = [$3-]
	@count = 0
	while (count < #folx)
	{
		@name = word($count $folx)
		
		@is = is_friend($name)
# friend	
		if (is == 1)
			{@printme = [$printme `6`b$name]}
# enemy			
		{if (is == 2)
			{@printme = [$printme `1$name]}
# normal			
		{if (is == 0)
			{@printme = [$printme `6$name]}
		}
		}
		@count = count + 1
	}
	echo $colorize($printme)
}

# auto op
on #^join 100 * {
	if (ischanop($N $1))
		{if (rmatch($0!$userhost() $aops)) {timer 1 mode $1 +o $0}}
}

# returns 0 if normal, 1 if friend, 2 if enemy
alias is_friend {
	@friend_name = strip(@ $0)
	@friend_name = strip(+ $friend_name)
	if (match($friend_name $friends))
		{@function_return = 1}
	{if (match($friend_name $enemies))
		{@function_return = 2}
		{@function_return = 0}
	}
}

# lag-o-meter
on ^raw_irc "%.% PONG *" {
	if ([$0]==[$S]) {
		^assign lagtime ${time()-mid(1 999 $3)}
		if (lagtime==0) {^set status_user no Lag }
		{^set status_user  Lag $lagtime }
	}
}
on -timer  * {
	^set STATUS_USER  Lag ?
	quote PING $time() $S
}

alias bk userhost $0 -cmd mode * -o+b $$0 *!*@$$4;timer 1 k $0 $1-

alias signoff {
	if ([$0]) {
		echo $colorize(`4*** `6Signoff: `b$N`6 \(`b$0-`6\))
		//signoff $0-
	}
	{
		echo $colorize(`4*** `6Signoff: `b$N`6 \(`b$signmsg`6\))
		//signoff $signmsg
	}
}

# DCC
on ^ctcp "* * DCC SEND *" { 
	if (autoget) {
		echo $colorize(`0`b[`4`bDCC`0`b] `6auto getting `b$4 `6from `b$0)
		dcc get $0 $4
	}
}

#------------------------------------------------------------------------------
# shit stolen from phoenix, rewrite

# for tab msg shit
alias getmsg {
@ msgcnt = msgcnt + [$0]
if (#msglist < msgcnt) {@ msgcnt = 1}
if (msgcnt <= 0) {@ msgcnt =  #msglist}
@ junk = K ## [m]
//type ^U$junk $^^{[$($msgcnt)]} 
}

alias addmsg {
@ matched = rmatch($0 $^\1-)
if (matched) {@ msglist = [$(0-${matched-1}) $(${matched+1}-)]}
{@ msglist = [$(0-${msgmax-1})]}
@ msgcnt = 0
^assign -matched
}
