Replacing tags with [Content Deleted]

As the title above, so basically whenever i say something like discord it will get tagged right? ######, but i want to switch it to the old [Content Deleted] by what i mean is
Do you have ######? ==> Do you have [Content Deleted]?
the problem is i have no idea on where to start, here is my current modulescript placed in chat modules.

local function run(chatService)
   local function tagToContentDeleted(speakerObj, messageObj, channelName)
      --what now
   end
   chatService:SetChatFilterMessage("tag_to_content_deleted", tagToContentDeleted)
end
return run

thanks, i prefer string patterns

4 Likes

I wanted to use gsub with string patterns but I just couldn’t get it to work right. I had (#([^$]+)) as the pattern, but it just wasn’t working as expected.

But here’s another option that works:

function tagsToContentDeleted(text)
	if string.find(text,'#') then
		local new = ''
		for i,v in pairs(string.split(text,' ')) do
			local s = v
			if string.find(v,'#') then
				s = '[Content Deleted]'
			end
			if i > 1 then
				s = ' '..s
			end
			new = new..s
		end
		return new
	else
		return text
	end
end

Input:

'2 #a# aaa ##'

Output:

2 [Content Deleted] aaa [Content Deleted]

However, I will note that this will probably easily spam the chat, so I wouldn’t really recommend doing this in the first place.

5 Likes

I just wanted to give my game an “old” feeling, but thank you so much

1 Like

I believe this is what you were originally aiming for when using gsub.

function tagsToContentDeleted(text:string)
	local str,_ = text:gsub("[#]+","[Content Deleted]")
	return str
end
4 Likes

This works even better, thank you both.

1 Like

You’re welcome. I also realized I could make this cleaner if I used the select function:

function tagsToContentDeleted(text:string)
	return select(1,text:gsub("[#]+","[Content Deleted]"))
end

:smiling_face_with_three_hearts:

local String = nil --This would be a reference to a string value.
String = string.gsub(String, "#+", "[ Content Deleted ]") --'String' is the input string.

Doesn’t need to be a function and you don’t need a character set (’[]’).

1 Like

I made it a function so it’d be simple (imo) to implement in his script where/however needed. Thanks for letting me know I didn’t need a character set, my gsub patterns are one of those things I just throw at the wall and if it works I leave it at that. :sweat_smile: