local M=game:GetService("\080\108\097\121\101\114\115")local D={"\047\116\101\097\109 ";"\047\116 ";"\037 "}function IsTeamCommand(M)for K=1,#D,1 do local W=D[K]if(string.sub(M,1,W:len())):lower()==W then return true end end return false end local K={}K.__index=K local W=require(script.Parent:WaitForChild("\085\116\105\108"))local f={}function K.EnterTeamChat(M)M.TeamChatEntered=true M.MessageModeButton.Size=UDim2.new(0,1000,1,0)M.MessageModeButton.Text="\091\084\101\097\109\093"M.MessageModeButton.TextColor3=M:GetTeamChatColor()local D=M.MessageModeButton.TextBounds.X M.MessageModeButton.Size=UDim2.new(0,D,1,0)M.TextBox.Size=UDim2.new(1,-D,1,0)M.TextBox.Position=UDim2.new(0,D,0,0)M.OriginalTeamText=M.TextBox.Text M.TextBox.Text=" "end function K.TextUpdated(M)local D=M.TextBox.Text if not M.TeamChatEntered then if IsTeamCommand(D)then M:EnterTeamChat()end else if D==""then M.MessageModeButton.Text=""M.MessageModeButton.Size=UDim2.new(0,0,0,0)M.TextBox.Size=UDim2.new(1,0,1,0)M.TextBox.Position=UDim2.new(0,0,0,0)M.TextBox.Text=""M.TeamChatEntered=false M.ChatBar:ResetCustomState()M.ChatBar:CaptureFocus()end end end function K.GetMessage(M)if M.TeamChatEntered then return"\047\116 "..M.TextBox.Text end return M.TextBox.Text end function K.ProcessCompletedMessage(M)return false end function K.Destroy(M)M.MessageModeConnection:disconnect()M.Destroyed=true end function K.GetTeamChatColor(D)local K=M.LocalPlayer if K.Team then return K.Team.TeamColor.Color end if D.ChatSettings.DefaultChannelNameColor then return D.ChatSettings.DefaultChannelNameColor end return Color3.fromRGB(35,76,142)end function f.new(M,D,W)local f=setmetatable({},K)f.Destroyed=false f.ChatWindow=M f.ChatBar=D f.ChatSettings=W f.TextBox=D:GetTextBox()f.MessageModeButton=D:GetMessageModeTextButton()f.OriginalTeamText=""f.TeamChatEntered=false f.MessageModeConnection=f.MessageModeButton.MouseButton1Click:connect(function()local M=f.TextBox.Text if string.sub(M,1,1)==" "then M=string.sub(M,2)end f.ChatBar:ResetCustomState()f.ChatBar:SetTextBoxText(M)f.ChatBar:CaptureFocus()end)f:EnterTeamChat()return f end function ProcessMessage(M,D,K,W)if K.TargetChannel=="\084\101\097\109"then return end if IsTeamCommand(M)then return f.new(D,K,W)end return nil end return{[W.KEY_COMMAND_PROCESSOR_TYPE]=W.IN_PROGRESS_MESSAGE_PROCESSOR;[W.KEY_PROCESSOR_FUNCTION]=ProcessMessage}
--!nonstrict
--	// FileName: Team.lua
--	// Written by: Partixel/TheGamer101
--	// Description: Team chat bar manipulation.

local PlayersService = game:GetService("Players")

local TEAM_COMMANDS = {"/team ", "/t ", "% "}

function IsTeamCommand(message)
	for i = 1, #TEAM_COMMANDS do
		local teamCommand = TEAM_COMMANDS[i]
		if string.sub(message, 1, teamCommand:len()):lower() == teamCommand then
			return true
		end
	end
	return false
end

local teamStateMethods = {}
teamStateMethods.__index = teamStateMethods

local util = require(script.Parent:WaitForChild("Util"))

local TeamCustomState = {}

function teamStateMethods:EnterTeamChat()
	self.TeamChatEntered = true
	self.MessageModeButton.Size = UDim2.new(0, 1000, 1, 0)
	self.MessageModeButton.Text = "[Team]"
	self.MessageModeButton.TextColor3 = self:GetTeamChatColor()

	local xSize = self.MessageModeButton.TextBounds.X
	self.MessageModeButton.Size = UDim2.new(0, xSize, 1, 0)
	self.TextBox.Size = UDim2.new(1, -xSize, 1, 0)
	self.TextBox.Position = UDim2.new(0, xSize, 0, 0)
	self.OriginalTeamText = self.TextBox.Text
	self.TextBox.Text = " "
end

function teamStateMethods:TextUpdated()
	local newText = self.TextBox.Text
	if not self.TeamChatEntered then
		if IsTeamCommand(newText) then
			self:EnterTeamChat()
		end
	else
		if newText == "" then
			self.MessageModeButton.Text = ""
			self.MessageModeButton.Size = UDim2.new(0, 0, 0, 0)
			self.TextBox.Size = UDim2.new(1, 0, 1, 0)
			self.TextBox.Position = UDim2.new(0, 0, 0, 0)
			self.TextBox.Text = ""
			---Implement this when setting cursor positon is a thing.
			---self.TextBox.Text = self.OriginalTeamText
			self.TeamChatEntered = false
			---Temporary until setting cursor position...
			self.ChatBar:ResetCustomState()
			self.ChatBar:CaptureFocus()
		end
	end
end

function teamStateMethods:GetMessage()
	if self.TeamChatEntered then
		return "/t " ..self.TextBox.Text
	end
	return self.TextBox.Text
end

function teamStateMethods:ProcessCompletedMessage()
	return false
end

function teamStateMethods:Destroy()
	self.MessageModeConnection:disconnect()
	self.Destroyed = true
end

function teamStateMethods:GetTeamChatColor()
	local LocalPlayer = PlayersService.LocalPlayer
	if LocalPlayer.Team then
		return LocalPlayer.Team.TeamColor.Color
	end
	if self.ChatSettings.DefaultChannelNameColor then
		return self.ChatSettings.DefaultChannelNameColor
	end
	return Color3.fromRGB(35, 76, 142)
end

function TeamCustomState.new(ChatWindow, ChatBar, ChatSettings)
	local obj = setmetatable({}, teamStateMethods)
	obj.Destroyed = false
	obj.ChatWindow = ChatWindow
	obj.ChatBar = ChatBar
	obj.ChatSettings = ChatSettings
	obj.TextBox = ChatBar:GetTextBox()
	obj.MessageModeButton = ChatBar:GetMessageModeTextButton()
	obj.OriginalTeamText = ""
	obj.TeamChatEntered = false

	obj.MessageModeConnection = obj.MessageModeButton.MouseButton1Click:connect(function()
		local chatBarText = obj.TextBox.Text
		if string.sub(chatBarText, 1, 1) == " " then
			chatBarText = string.sub(chatBarText, 2)
		end
		obj.ChatBar:ResetCustomState()
		obj.ChatBar:SetTextBoxText(chatBarText)
		obj.ChatBar:CaptureFocus()
	end)

	obj:EnterTeamChat()

	return obj
end

function ProcessMessage(message, ChatWindow, ChatBar, ChatSettings)
	if ChatBar.TargetChannel == "Team" then
		return
	end

	if IsTeamCommand(message) then
		return TeamCustomState.new(ChatWindow, ChatBar, ChatSettings)
	end
	return nil
end

return {
	[util.KEY_COMMAND_PROCESSOR_TYPE] = util.IN_PROGRESS_MESSAGE_PROCESSOR,
	[util.KEY_PROCESSOR_FUNCTION] = ProcessMessage
}
