local a=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local L=game:GetService("\084\101\120\116\083\101\114\118\105\099\101")local I=a("\080\114\111\109\105\115\101")local R={}function R.GetNonChatStringForBroadcastAsync(a,I)local R=nil local X,P=pcall(function()local X=L:FilterStringAsync(a,I)if not X then error("\078\111 \084\101\120\116\070\105\108\116\101\114\082\101\115\117\108\116")end R=X:GetNonChatStringForBroadcastAsync()end)if not X then return false,P end return R end function R.PromiseNonChatStringForBroadcast(a,L)assert(type(a)=="\115\116\114\105\110\103")assert(type(L)=="\110\117\109\098\101\114")local X=I.spawn(function(I,X)local P,A=R.GetNonChatStringForBroadcastAsync(a,L)if not P then return X(A or"\080\099\097\108\108 \102\097\105\108\101\100")end if not P then return X("\078\111 \116\101\120\116")end I(P)end)return X end return R
---
-- @module TextFilterUtil
-- @author Quenty

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local TextService = game:GetService("TextService")

local Promise = require("Promise")

local TextFilterUtil = {}

function TextFilterUtil.GetNonChatStringForBroadcastAsync(string, userId)
	local text = nil
	local ok, err = pcall(function()
		local result = TextService:FilterStringAsync(string, userId)
		if not result then
			error("No TextFilterResult")
		end

		text = result:GetNonChatStringForBroadcastAsync()
	end)

	if not ok then
		return false, err
	end

	return text
end

function TextFilterUtil.PromiseNonChatStringForBroadcast(string, userId)
	assert(type(string) == "string")
	assert(type(userId) == "number")

	local promise = Promise.spawn(function(resolve, reject)
		local text, err = TextFilterUtil.GetNonChatStringForBroadcastAsync(string, userId)
		if not text then
			return reject(err or "Pcall failed")
		end
		if not text then
			return reject("No text")
		end

		resolve(text)
	end)

	return promise
end

return TextFilterUtil