local function C(C,s)local p=CreateIfDoesntExist(C,s,"\082\101\109\111\116\101\069\118\101\110\116")p.OnServerEvent:Connect(emptyFunction)return p end C(EventFolder,"\079\110\078\101\119\077\101\115\115\097\103\101")C(EventFolder,"\079\110\077\101\115\115\097\103\101\068\111\110\101\070\105\108\116\101\114\105\110\103")C(EventFolder,"\079\110\078\101\119\083\121\115\116\101\109\077\101\115\115\097\103\101")C(EventFolder,"\079\110\067\104\097\110\110\101\108\074\111\105\110\101\100")C(EventFolder,"\079\110\067\104\097\110\110\101\108\076\101\102\116")C(EventFolder,"\079\110\077\117\116\101\100")C(EventFolder,"\079\110\085\110\109\117\116\101\100")C(EventFolder,"\079\110\077\097\105\110\067\104\097\110\110\101\108\083\101\116")C(EventFolder,"\067\104\097\110\110\101\108\078\097\109\101\067\111\108\111\114\085\112\100\097\116\101\100")C(EventFolder,"\083\097\121\077\101\115\115\097\103\101\082\101\113\117\101\115\116")C(EventFolder,"\083\101\116\066\108\111\099\107\101\100\085\115\101\114\073\100\115\082\101\113\117\101\115\116")CreateIfDoesntExist(EventFolder,"\071\101\116\073\110\105\116\068\097\116\097\082\101\113\117\101\115\116","\082\101\109\111\116\101\070\117\110\099\116\105\111\110")CreateIfDoesntExist(EventFolder,"\077\117\116\101\080\108\097\121\101\114\082\101\113\117\101\115\116","\082\101\109\111\116\101\070\117\110\099\116\105\111\110")CreateIfDoesntExist(EventFolder,"\085\110\077\117\116\101\080\108\097\121\101\114\082\101\113\117\101\115\116","\082\101\109\111\116\101\070\117\110\099\116\105\111\110")EventFolder=useEvents local function s(C)local s=ChatService:GetSpeaker(C.Name)if s then ChatService:RemoveSpeaker(C.Name)end s=ChatService:InternalAddSpeakerWithPlayerObject(C.Name,C,false)for C,p in pairs(ChatService:GetAutoJoinChannelList())do s:JoinChannel(p.Name)end s:InternalAssignEventFolder(EventFolder)s.ChannelJoined:connect(function(p,A)local E=nil local K=nil local W=ChatService:GetChannel(p)if W then E=W:GetHistoryLogForSpeaker(s)K=W.ChannelNameColor end EventFolder.OnChannelJoined:FireClient(C,p,A,E,K)end)s.Muted:connect(function(s,p,A)EventFolder.OnMuted:FireClient(C,s,p,A)end)s.Unmuted:connect(function(s)EventFolder.OnUnmuted:FireClient(C,s)end)ChatService:InternalFireSpeakerAdded(s.Name)end EventFolder.SayMessageRequest.OnServerEvent:connect(function(C,s,p)if type(s)~="\115\116\114\105\110\103"then return elseif not validateMessageLength(s)then return end if type(p)~="\115\116\114\105\110\103"then return elseif not validateChannelNameLength(p)then return end local A=ChatService:GetSpeaker(C.Name)if A then if C.Chat.Value==true then return A:SayMessage(s,p)end end return nil end)EventFolder.MutePlayerRequest.OnServerInvoke=function(C,s)if type(s)~="\115\116\114\105\110\103"then return end local p=ChatService:GetSpeaker(C.Name)if p then local C=ChatService:GetSpeaker(s)if C then p:AddMutedSpeaker(C.Name)return true end end return false end EventFolder.UnMutePlayerRequest.OnServerInvoke=function(C,s)if type(s)~="\115\116\114\105\110\103"then return end local p=ChatService:GetSpeaker(C.Name)if p then local C=ChatService:GetSpeaker(s)if C then p:RemoveMutedSpeaker(C.Name)return true end end return false end
--// All remote events will have a no-opt OnServerEvent connecdted on construction
local function CreateEventIfItDoesntExist(parentObject, objectName)
	local obj = CreateIfDoesntExist(parentObject, objectName, "RemoteEvent")
	obj.OnServerEvent:Connect(emptyFunction)
	return obj
end

CreateEventIfItDoesntExist(EventFolder, "OnNewMessage")
CreateEventIfItDoesntExist(EventFolder, "OnMessageDoneFiltering")
CreateEventIfItDoesntExist(EventFolder, "OnNewSystemMessage")
CreateEventIfItDoesntExist(EventFolder, "OnChannelJoined")
CreateEventIfItDoesntExist(EventFolder, "OnChannelLeft")
CreateEventIfItDoesntExist(EventFolder, "OnMuted")
CreateEventIfItDoesntExist(EventFolder, "OnUnmuted")
CreateEventIfItDoesntExist(EventFolder, "OnMainChannelSet")
CreateEventIfItDoesntExist(EventFolder, "ChannelNameColorUpdated")

CreateEventIfItDoesntExist(EventFolder, "SayMessageRequest")
CreateEventIfItDoesntExist(EventFolder, "SetBlockedUserIdsRequest")
CreateIfDoesntExist(EventFolder, "GetInitDataRequest", "RemoteFunction")
CreateIfDoesntExist(EventFolder, "MutePlayerRequest", "RemoteFunction")
CreateIfDoesntExist(EventFolder, "UnMutePlayerRequest", "RemoteFunction")

EventFolder = useEvents

local function CreatePlayerSpeakerObject(playerObj)
	--// If a developer already created a speaker object with the
	--// name of a player and then a player joins and tries to
	--// take that name, we first need to remove the old speaker object
	local speaker = ChatService:GetSpeaker(playerObj.Name)
	if speaker then
		ChatService:RemoveSpeaker(playerObj.Name)
	end

	speaker = ChatService:InternalAddSpeakerWithPlayerObject(playerObj.Name, playerObj, false)

	for _, channel in pairs(ChatService:GetAutoJoinChannelList()) do
		speaker:JoinChannel(channel.Name)
	end

	speaker:InternalAssignEventFolder(EventFolder)

	speaker.ChannelJoined:connect(function(channel, welcomeMessage)
		local log = nil
		local channelNameColor = nil

		local channelObject = ChatService:GetChannel(channel)
		if channelObject then
			log = channelObject:GetHistoryLogForSpeaker(speaker)
			channelNameColor = channelObject.ChannelNameColor
		end
		EventFolder.OnChannelJoined:FireClient(playerObj, channel, welcomeMessage, log, channelNameColor)
	end)

	speaker.Muted:connect(function(channel, reason, length)
		EventFolder.OnMuted:FireClient(playerObj, channel, reason, length)
	end)

	speaker.Unmuted:connect(function(channel)
		EventFolder.OnUnmuted:FireClient(playerObj, channel)
	end)

	ChatService:InternalFireSpeakerAdded(speaker.Name)
end

EventFolder.SayMessageRequest.OnServerEvent:connect(function(playerObj, message, channel)
	if type(message) ~= "string" then
		return
	elseif not validateMessageLength(message) then
		return
	end

	if type(channel) ~= "string" then
		return
	elseif not validateChannelNameLength(channel) then
		return
	end

	local speaker = ChatService:GetSpeaker(playerObj.Name)
	if speaker then
		if playerObj.Chat.Value == true then
			return speaker:SayMessage(message, channel)
		end
	end

	return nil
end)

EventFolder.MutePlayerRequest.OnServerInvoke = function(playerObj, muteSpeakerName)
	if type(muteSpeakerName) ~= "string" then
		return
	end

	local speaker = ChatService:GetSpeaker(playerObj.Name)
	if speaker then
		local muteSpeaker = ChatService:GetSpeaker(muteSpeakerName)
		if muteSpeaker then
			speaker:AddMutedSpeaker(muteSpeaker.Name)
			return true
		end
	end
	return false
end

EventFolder.UnMutePlayerRequest.OnServerInvoke = function(playerObj, unmuteSpeakerName)
	if type(unmuteSpeakerName) ~= "string" then
		return
	end

	local speaker = ChatService:GetSpeaker(playerObj.Name)
	if speaker then
		local unmuteSpeaker = ChatService:GetSpeaker(unmuteSpeakerName)
		if unmuteSpeaker then
			speaker:RemoveMutedSpeaker(unmuteSpeaker.Name)
			return true
		end
	end
	return false
end
