ULX

Author Topic: Admin sounds, tools and other code chat.  (Read 56104 times)

0 Members and 4 Guests are viewing this topic.

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #30 on: April 12, 2008, 03:11:42 PM »
This only filters out the word "", BTW the forums sensored the other two words

Code: [Select]
WordD = { "<censor>" }
local WordC = ""
function WFilter( ply, text, toall )
         for _, v in ipairs( WordD ) do
             if string.find( text, v) then
                WordC = string.Replace(text,v,"****")
                else
                WordC = (text)
             end
         end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );
« Last Edit: April 12, 2008, 04:40:37 PM by Megiddo »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Admin sounds, tools and other code chat.
« Reply #31 on: April 12, 2008, 04:40:05 PM »
Ok, so is this what you're saying?

Code: [Select]
WordD = { "<censor>", "ass", "<censor>" }
local WordC = ""
function WFilter( ply, text, toall )
         for _, v in pairs( WordD ) do
             if string.find( text, v) then
                WordC = string.Replace(text,v,"****")
                else
                WordC = (text)
             end
         end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );

BTW, thanks for the move, and all the help you've given me so far.

Untested, but try this
Code: [Select]
WordD = { "word" }
function WFilter( ply, text, toall )
local found = false
for _, v in pairs( WordD ) do
if string.find( text, v) then
text:gsub(v,"****")
found = true
end
end

if found then return text end
end
hook.Add( "PlayerSay", "WFilter", WFilter );
Experiencing God's grace one day at a time.

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #32 on: April 12, 2008, 05:10:06 PM »
Quote
Untested, but try this

Code:
WordD = { "word" }
function WFilter( ply, text, toall )
   local found = false
   for _, v in pairs( WordD ) do
      if string.find( text, v) then
         text:gsub(v,"****")
         found = true
      end
   end

   if found then return text end
end
hook.Add( "PlayerSay", "WFilter", WFilter );

Tested, doesn't work

Code: [Select]
WordD = { "<censor>" }
local WordC = ""
function WFilter( ply, text, toall )
         for _, v in ipairs( WordD ) do
             if string.find( text, v) then
                WordC = string.Replace(text,v,"****")
                else
                WordC = (text)
             end
         end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );

this one sensors out the last word in the WordD string , but breaks the ulx chat commands.
« Last Edit: April 12, 2008, 05:12:31 PM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #33 on: April 12, 2008, 06:09:08 PM »
But, do you know why this script isn't working at all?

Two possibilities.

1) Tried removing the ( ) from your WordC= (text) ? Not sure why you have it. Pretty sure it's not needed.

2) http://www.lua.org/manual/5.1/manual.html#pdf-string.find - String find does pattern matching by default. Patterns are nice (but can be complex) ways of defining exactly what to look for without having to type more than necessary or make it easier to search for things that are hard to type (spaces for instance, special ascii characters, etc.)
Try changing your string.find to
string.find( text, v, 1, true)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #34 on: April 12, 2008, 06:28:36 PM »
Two possibilities.

1) Tried removing the ( ) from your WordC= (text) ? Not sure why you have it. Pretty sure it's not needed.

2) http://www.lua.org/manual/5.1/manual.html#pdf-string.find - String find does pattern matching by default. Patterns are nice (but can be complex) ways of defining exactly what to look for without having to type more than necessary or make it easier to search for things that are hard to type (spaces for instance, special ascii characters, etc.)
Try changing your string.find to
string.find( text, v, 1, true)

Tested, but still this code only censors word2. Any idea as to why?

Code: [Select]
WordD = { "word1" , "word2" }
local WordC = ""
function WFilter( ply, text, toall )
         for _, v in ipairs( WordD ) do
             if string.find( text, v, 1, true) then
                WordC = string.Replace(text,v,"****")
                else
                WordC = (text)
             end
         end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #35 on: April 12, 2008, 09:36:17 PM »
Tested, but still this code only censors word2. Any idea as to why?

Code: [Select]
WordD = { "word1" , "word2" }
local WordC = ""
function WFilter( ply, text, toall )
         for _, v in ipairs( WordD ) do
             if string.find( text, v, 1, true) then
                WordC = string.Replace(text,v,"****")
                else
                WordC = (text)
             end
         end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );

I really hate lightbulb moments that show my stupidity.
I have a very good idea why.
This is 100% sillyness on my part (and maybe even others who attempted to help), nothing on you, as it is a mistake that a new coder (of _any_ language) could make.
WordC gets replaced with non-replaced "text" every single time it comes across a non-tabled word.

Code: [Select]
WordD = { "word1" , "word2" }
local WordC = ""
function WFilter( ply, text, toall )
         WordC = text
         for _, v in ipairs( WordD ) do
             if string.find( WordC, v, 1, true) then
                WordC = string.Replace(WordC, v,"****")
             end
         end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );

That should work. Hope you understand the difference. Your loop was setting WordC back to straight text on words not in the table.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #36 on: April 13, 2008, 08:39:36 AM »
Again, same thing. Only censors word2 and breaks the ulx chat commands. Console doesn't return any errors, and I've ran lua_run PrintTable(WordD) and it shows everything as it should be. When we get this finished though I would like to see it released as a module with ulx because offensive language can get to be intolerable at times.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #37 on: April 13, 2008, 12:09:33 PM »
Again, same thing. Only censors word2 and breaks the ulx chat commands. Console doesn't return any errors, and I've ran lua_run PrintTable(WordD) and it shows everything as it should be. When we get this finished though I would like to see it released as a module with ulx because offensive language can get to be intolerable at times.

I tried it in singleplayer. The last code I gave you works fine, except yes, it breaks ULX chat commands.
I don't think it should break ALL chat hooks, but apparently not returning nil does.
I do not know why your examples aren't working.
Where are you testing this? What are you modifying? If testing on a dedicated server, are you restarting the server (not just the map) each change you make so that lua cache can be rebuilt?
I first said "This is a test of word1 word2"
It returned JamminR: this is a test of **** ****
I then said " This is a test of word1 and word2"
It returned JamminR: This is a test of **** and ****

Though you are more than welcome to make a release on your own, we will not add a word filter to ULX.
We've considered this a few times in the past and realized that it would be an effort in futility. As soon as you censor one word on a server, what I call the Gmod immature level increases 10 fold, and many on a server would start trying to find ways around the censor instead of building. I've seen it before with IRC chat bots back in the early 90s. People would get kicked from an IRC channel if they said a bad word, so instead, they'd rejoin and the only chat they'd do for 10 minutes or more (until a real admin banned them) would be to start replacing letters with numbers/symbols to represent another letter. It wouldn't surprise me one bit if 'leet speech' was invented by people doing such work arounds. Though you could increase the word table, that would start slowing down the script.
« Last Edit: April 13, 2008, 12:15:46 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #38 on: April 13, 2008, 12:24:27 PM »
Ok, thank you very much. I didn't restart the server, I just did the map. Also do you know of a way I can keep it from breaking the ulx chat commands, and how do I make it an addon?
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #39 on: April 13, 2008, 12:30:40 PM »
I do not know how to prevent it from breaking other chat commands. You may wish to look into ULX to see how we do it, as I don't remember off the top of my head.

Addons are like virtual gmod folders.
Your folder would be something like the following
<addon_name>
in <addon_name> is required an info.txt. Look up one of your other addons for how that file is formatted.
Then, in <addon_name> folder, you place what folders/files that would be added to the Gmod folder if we were manually adding them.
In this case, you would need
<addon_name>/lua
<addon_name>/lua/autorun
<addon_name>/lua/autorun/filename.lua

There are other ways for larger lua files, where you just make the autorun link to those files but your script probably doesn't require a separate load.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #40 on: April 13, 2008, 12:35:30 PM »
Thank You!
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #41 on: April 13, 2008, 12:43:41 PM »
Perhaps you could write a client side censor instead using Client hook "chattext" and have your server send it to clients.
http://garrysmod.com/wiki/?title=Gamemode.ChatText

No idea if this would break other things or not.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #42 on: April 13, 2008, 01:36:17 PM »
I tried, but I couldn't figure out how to make it work without using playersay. Maybe I could modify ulx to get it's player text from WordC rather than text

An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #43 on: April 13, 2008, 03:37:07 PM »
I was just looking at Megiddo's code example above. I believe his won't break ulx commands unless they include some of those censored words (such as in the name of the player or the reason provided for ban/kick).

You're always returning WordC/text, modified or not.
Gmod chat hooks will always stop other hooks from functioning if anything but nil is returned. (as we've discussed)
However, Megiddo uses a 'return' if nothing was found/edited, or the modified text if something was.

You can use his, or make slight modification to yours code that would look like the following
Code: [Select]
WordD = { "word1" , "word2" }
function WFilter( ply, text, toall )
local WordC = nil
         for _, v in ipairs( WordD ) do
             if string.find( text, v, 1, true) then
                WordC = string.Replace(text,v,"****")
               end
         end
if WordC then return WordC else return end
end
hook.Add( "PlayerSay", "WFilter", WFilter )

In that code, WordC always gets set to nil everytime something is said.
If a censored word is found, it gets set in WordC. If not, WordC remains nil.
After it loops, if WordC has text, it is returned censored. If not, the hook is returned nothing, which should allow other scripts, such as ULX, to see the chat.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #44 on: April 13, 2008, 03:47:24 PM »
Tested and got this

word1
****
word2
****
word1 and word2
word1 and ****

word2 and word1
**** and word1

and it didn't break ulx
« Last Edit: April 13, 2008, 03:52:30 PM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly