[XP] RMX-OS Chat Filter

Started by nathmatt, January 08, 2011, 09:08:56 am

Previous topic - Next topic

nathmatt

January 08, 2011, 09:08:56 am Last Edit: January 26, 2011, 06:59:59 pm by nathmatt
RMX-OS Chat Filter
Authors: Nathmatt
Version: 2.2
Type: Message Filter
Key Term: RMX-OS Plugin



Introduction

filters game messages


Features


  • Easy to add words to filter

  • Easy to add word to filter it with

  • Now removes any indication of the word




Screenshots

not really needed


Demo

no demo


Script

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# RMX-OS Chat Filter by Nathmatt
# Version: 2.2
# Type: Message filter
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#   
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
module Chat_Filter
 
  Flitered_Words = ['crap']
  Non_Filtered   = ['scrap']
  Replace_With   ='***'
 
end

class RMXOS::Network
 
  alias filter_add_message add_message
  def add_message(id, message, color, action = false)
    if @players[id] != nil
      message = filter_messages(message)
    end
    filter_add_message(id, message, color, action = false)
  end
 
  def filter_messages(text)
    message = text.dup
    text.each(' '){|word|
    w = word.downcase
    if !Chat_Filter::Non_Filtered.include?(w)
      Chat_Filter::Flitered_Words.each{|filter|
      if w.gsub!("#{filter}") {''} != nil
        message.gsub!("#{word}") {Chat_Filter::Replace_With+' '}
      end}
    end}
    return message
  end

end



Instructions

just place this below RMX-OS and above main



Compatibility

no issues known


Credits and Thanks


  • Nathmatt




Author's Notes

if a word includes the filtered word the entire word is replaced unless it is included in the Non_Filtered array

post any bugs or suggestions here
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Noob

Thanks very much for making this:)! I'll be sure to try it out and tell you about any problems I find.

Noob

Ok, just a few problems and suggestions for improvement: first of all, if you say the word within another then it isn't filtered (doesn't really matter, and I didn't specify it, just pointint it out). Also, now whenever the player talks a small non-game info box comes up telling them each word they say. This causes great inconvenience during gameplay, because it goes one word at a time. This is especially inconvenient when the player types /cmd, because it tells them all the commands one word at a time, and in the actual chatbox they are all jumbled together into one unreadable streak of gray text. As for the text in the chatbox, it is all squeezed into one line now, whereas beforehand it was split into different lines so it was readable. Also, when the server gives the player a message, such as "Bob has join the party," there are no spaces, so it looks like "Bobhasjoinedtheparty."

Wizered67

January 08, 2011, 11:24:07 am #3 Last Edit: January 08, 2011, 11:32:44 am by Wizered67
The reason the things pop up is because nathmatt left debug stuff in. Just delete the lines that only say
p whatevericantremember
. The other problems I don't know. Oh, and one bug I found is that if you put an exclamation point after a word it gets through.
Edit: I'm not getting the no space error so I'm not sure why you are.... Did you do anything weird to the script....

nathmatt

update 1.5 it now removes any indication of the word in that capitalization i hope to figure out a way to fix that
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


ForeverZer0

January 08, 2011, 02:50:07 pm #5 Last Edit: January 08, 2011, 02:51:08 pm by ForeverZer0
text.downcase.gsub!

Just have all the bad words you define be in all lower case.

You could also include a few regular expessions to not have it replace words that are with in other words.

ex. "ass" is a bad word.

the word "assisstance" would look like this: "***isstance"


EDIT: Nevermind the capitilization. I see you said you fixed that. oops.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

nathmatt

i thought of using.downcase but then nothing you typed would every be capitalized
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


ForeverZer0

Don't use downcase!, use downcase.
If you scripted it right it would not modify the original string, but only scan it for bad words in all lower case. It won't actually change it unless you are doing something like this.


old_string = 'HEY THIS IS CAPS'
new_string = old_string.downcase.gsub('caps') { '***' }


This returns: "hey this is ***"

If you simply do this, the capitilization remains the same:


old_string = 'HEY THIS IS CAPS'
old_string.downcase.gsub!('caps') { '***' }


This returns: "HEY THIS IS ***"
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

nathmatt

update 2.0 fixed it the entire word gets replaced unless it is included in the Non_Filtered array
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


mroedesigns

Hey, awesome script!

I found an issue though. If the string is multiple words, and the first word is filtered, it crashes on line 61 with 'ArgumentError Occurred'.

text.each(' '){|word|Chat_Filter::Flitered_Words.each{|filter|

nathmatt

update 2.1 fixed above error had to do with editing the string i was going trough so i just duplicated it using .dup
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Noob

Thanks, everything seems to work now!

Noob

Hey I've got a minor issue with this, nothing horrible, but i was wondering if it's fixable. When a user types /cmd to see the commands, certain ones are blotted out if "ass" is a bad word. For instance, /newpass. Even if I make it a non-filtered word, it's still blotted out in /cmd. Any ideas?

nathmatt

Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script