# It gives me this line in partyline:
# [16:26] <<kz`joe>> !kz`joe! .changeplayer team1 1 ompa
#
# I think it's my regsub down there, returning 1 or something..

proc cupBot:Change_Player_In_Team {nick userhost handle channel text} {
	global cB
	set nick [join [lrange [split $nick] 0 0]]
	set newnick [join [lrange [split $text] 2 2]]
	if {![isop $nick $cB(Channel)]} { return 0 }
	if {$cB(CupInfo:Active) == 0 || $cB(Added:Current) != $cB(Added:Full)} { CupFunction:SendMessage $cB(Channel) $cB(Message:Status:No_Active_Cup);return 0 }
	if {[lindex $text 1] != 1 && [lindex $text 1] != 2} {
		set message $cB(Message:Change_Player_Usage)
		set message [CupFunction:ReplaceCookie $message %trigger% $cB(Trigger:Change_Player)]
		CupFunction:SendMessage $cB(Channel) $message
		return 0
	}
	if {[lindex $text 2] == ""} {
		set message $cB(Message:Change_Player_Usage)
		set message [CupFunction:ReplaceCookie $message %trigger% $cB(Trigger:Change_Player)]
		CupFunction:SendMessage $cB(Channel) $message
		return 0
	}

	if {[regexp -nocase {team(\d+)} [lindex $text 0] "" matchnumber]} {
		set player [lindex [split $cB(CupInfo:Team$matchnumber)] [expr [lindex $text 1] - 1]]
		regsub "[CupFunction:Filter $player]" $cB(CupInfo:Team$matchnumber) "$newnick" cB(CupInfo:Team$matchnumber)

	} else {
		set message $cB(Message:Change_Player_Usage)
		set message [CupFunction:ReplaceCookie $message %trigger% $cB(Trigger:Change_Player)]
		CupFunction:SendMessage $cB(Channel) $message
		return 0
	}
	
}
