Smeers
|
  |
| Joined: 14 Feb 2013 |
| Total Posts: 797 |
|
|
| 09 Jul 2016 12:43 PM |
local filter = { ['wordtofilter'] = "wordtoreplaceitwith", }
local function filterText(Text) for Word,Replacement in next, filter do Text = Text:gsub(Word,Replacement) end return Text end
This function works to filter specified words into different words as a replacement.
In this case, it would replace the message "wordtofilter" to "wordtoreplaceitwith".
But if someone entered "WORDtoFILTER", it would still return "WORDtoFILTER".
Could someone solve this for me? I don't think I can use gsub and I'm not too good with string manipulation. |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2016 12:44 PM |
| Text = Text:gsub(Word:lower(),Replacement) |
|
|
| Report Abuse |
|
|
Smeers
|
  |
| Joined: 14 Feb 2013 |
| Total Posts: 797 |
|
|
| 09 Jul 2016 12:46 PM |
This makes the word in the table lowercase, thus doing nothing (even if I made it uppercase).
Anyone have a working method? |
|
|
| Report Abuse |
|
|
Smeers
|
  |
| Joined: 14 Feb 2013 |
| Total Posts: 797 |
|
|
| 09 Jul 2016 12:48 PM |
| I could actually loop through each string finding each and every uppercase/lowercase combonation and include it in the filtering table automatically with a for loop, but this would cause at least a second delay in sending chat messages in my custom chat (which is what this is for). |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2016 12:50 PM |
Oh my bad
Text = Text:lower():gsub(Word,Replacement)
lol |
|
|
| Report Abuse |
|
|
Smeers
|
  |
| Joined: 14 Feb 2013 |
| Total Posts: 797 |
|
|
| 09 Jul 2016 12:52 PM |
| Wouldn't that make every single character in the message a lowercase character? :/ |
|
|
| Report Abuse |
|
|
|
| 09 Jul 2016 12:53 PM |
Well obviously. That's how you filter.
The only other way would to be loop over every word but I cbb to write the code for that since this way is so much easier |
|
|
| Report Abuse |
|
|
Smeers
|
  |
| Joined: 14 Feb 2013 |
| Total Posts: 797 |
|
|
| 09 Jul 2016 12:55 PM |
I'll just make a function that automatically finds all character combonations of uppercase/lowercase and add that to the list on server boot.
|
|
|
| Report Abuse |
|
|
|
| 09 Jul 2016 12:59 PM |
| Looping over all the words would be easier |
|
|
| Report Abuse |
|
|