function methods.InternalApplyRobloxFilterNewAPI(w,c,E)local Q=false local g=RunService:IsServer()if Q or g then local Q=w:GetSpeaker(c)if Q==nil then return false,nil,nil end local g=Q:GetPlayer()if g==nil then return true,false,E end local F,r=pcall(function()local c=game:GetService("\084\101\120\116\083\101\114\118\105\099\101")local w=c:FilterStringAsync(E,g.UserId)return w end)if F then return true,true,r else warn("\069\114\114\111\114 \102\105\108\116\101\114\105\110\103 \109\101\115\115\097\103\101\058",E)w:InternalNotifyFilterIssue()return false,nil,nil end else task.wait(.2)return true,false,E end return nil end function methods.InternalDoMessageFilter(Q,c,E,w)local g=Q.FilterMessageFunctions:GetIterator()for Q,g,F in g do local r,J=pcall(function()g(c,E,w)end)if not r then warn(string.format("\068\111\077\101\115\115\097\103\101\070\105\108\116\101\114 \070\117\110\099\116\105\111\110 \'\037\115\' \102\097\105\108\101\100 \102\111\114 \114\101\097\115\111\110\058 \037\115",Q,J))end end end function methods.InternalDoProcessCommands(Q,c,E,w)local g=Q.ProcessCommandsFunctions:GetIterator()for Q,g,F in g do local r,J=pcall(function()local Q=g(c,E,w)if type(Q)~="\098\111\111\108\101\097\110"then error("\080\114\111\099\101\115\115 \099\111\109\109\097\110\100 \102\117\110\099\116\105\111\110\115 \109\117\115\116 \114\101\116\117\114\110 \097 \098\111\111\108")end return Q end)if not r then warn(string.format("\068\111\080\114\111\099\101\115\115\067\111\109\109\097\110\100\115 \070\117\110\099\116\105\111\110 \'\037\115\' \102\097\105\108\101\100 \102\111\114 \114\101\097\115\111\110\058 \037\115",Q,J))elseif J then return true end end return false end function methods.InternalGetUniqueMessageId(c)local E=c.MessageIdCounter c.MessageIdCounter=E+1 return E end function methods.InternalAddSpeakerWithPlayerObject(Q,c,E,w)if Q.Speakers[c:lower()]then error("\083\112\101\097\107\101\114 \""..(c.."\" \097\108\114\101\097\100\121 \101\120\105\115\116\115\033"))end local g=Speaker.new(Q,c)g:InternalAssignPlayerObject(E)Q.Speakers[c:lower()]=g if w then local E,w=pcall(function()Q.eSpeakerAdded:Fire(c)end)if not E and w then print("\069\114\114\111\114 \097\100\100\105\110\103 \115\112\101\097\107\101\114\058 "..w)end end return g end function methods.InternalFireSpeakerAdded(E,c)local w,Q=pcall(function()E.eSpeakerAdded:Fire(c)end)if not w and Q then print("\069\114\114\111\114 \102\105\114\105\110\103 \115\112\101\097\107\101\114 \097\100\100\101\100\058 "..Q)end end

function methods:InternalApplyRobloxFilterNewAPI(speakerName, message) --// USES FFLAG
	local alwaysRunFilter = false
	local runFilter = RunService:IsServer() -- and not RunService:IsStudio()
	if (alwaysRunFilter or runFilter) then
		local fromSpeaker = self:GetSpeaker(speakerName)
		if fromSpeaker == nil then
			return false, nil, nil
		end
		
		local fromPlayerObj = fromSpeaker:GetPlayer()
		if fromPlayerObj == nil then
			return true, false, message
		end

		local success, filterResult = pcall(function()
			local ts = game:GetService("TextService")
			local result = ts:FilterStringAsync(message, fromPlayerObj.UserId)
			return result
		end)
		if (success) then
			return true, true, filterResult
		else
			warn("Error filtering message:", message)
			self:InternalNotifyFilterIssue()
			return false, nil, nil
		end
	else
		--// Simulate filtering latency.
		task.wait(0.2)
		return true, false, message
	end

	return nil
end

function methods:InternalDoMessageFilter(speakerName, messageObj, channel)
	local filtersIterator = self.FilterMessageFunctions:GetIterator()

	for funcId, func, priority in filtersIterator do
		local success, errorMessage = pcall(function()
			func(speakerName, messageObj, channel)
		end)

		if not success then
			warn(string.format("DoMessageFilter Function '%s' failed for reason: %s", funcId, errorMessage))
		end
	end
end

function methods:InternalDoProcessCommands(speakerName, message, channel)
	local commandsIterator = self.ProcessCommandsFunctions:GetIterator()

	for funcId, func, priority in commandsIterator do
		local success, returnValue = pcall(function()
			local ret = func(speakerName, message, channel)
			if type(ret) ~= "boolean" then
				error("Process command functions must return a bool")
			end
			return ret
		end)

		if not success then
			warn(string.format("DoProcessCommands Function '%s' failed for reason: %s", funcId, returnValue))
		elseif returnValue then
			return true
		end
	end

	return false
end

function methods:InternalGetUniqueMessageId()
	local id = self.MessageIdCounter
	self.MessageIdCounter = id + 1
	return id
end

function methods:InternalAddSpeakerWithPlayerObject(speakerName, playerObj, fireSpeakerAdded)
	if (self.Speakers[speakerName:lower()]) then
		error("Speaker \"" .. speakerName .. "\" already exists!")
	end

	local speaker = Speaker.new(self, speakerName)
	speaker:InternalAssignPlayerObject(playerObj)
	self.Speakers[speakerName:lower()] = speaker

	if fireSpeakerAdded then
		local success, err = pcall(function() self.eSpeakerAdded:Fire(speakerName) end)
		if not success and err then
			print("Error adding speaker: " ..err)
		end
	end

	return speaker
end

function methods:InternalFireSpeakerAdded(speakerName)
	local success, err = pcall(function() self.eSpeakerAdded:Fire(speakerName) end)
	if not success and err then
		print("Error firing speaker added: " ..err)
	end
end
