Skip to content

Commit

Permalink
Chat Filter (#6901)
Browse files Browse the repository at this point in the history
# About the pull request
Adds a chat filter which automatically prevents messages in-character,
OOC, LOOC or dchat from being sent if they contain certain words, this
will notify the user and warn them that they will be banned should they
try to circumvent it.

This is obviously just a config option so if this is merged the config
will have to be edited accordingly.
<!-- Remove this text and explain what the purpose of your PR is.

Mention if you have tested your changes. If you changed a map, make sure
you used the mapmerge tool.
If this is an Issue Correction, you can type "Fixes Issue #169420" to
link the PR to the corresponding Issue number #169420.

Remember: something that is self-evident to you might not be to others.
Explain your rationale fully, even if you feel it goes without saying.
-->

# Explain why it's good for the game
Instead of instantly banning people for saying certain words, simply
prevents them from saying them in the first place - this way no harm is
done to anyone who might be offended as well as the player which
(possibly mistakenly) said the word not being banned and instead let
know the word is not allowed.
# Testing Photographs and Procedure
<details>
<summary>Screenshots & Videos</summary>

Put screenshots and videos here with an empty line between the
screenshots and the `<details>` tags.

</details>


# Changelog
:cl:
config: Added config options for filtering out certain words
/:cl:

---------

Co-authored-by: harryob <[email protected]>
  • Loading branch information
Git-Nivrak and harryob authored Aug 22, 2024
1 parent 62e7681 commit d628fc6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
14 changes: 7 additions & 7 deletions code/controllers/configuration/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
var/motd
var/policy

var/static/regex/ic_filter_regex
var/static/regex/word_filter_regex

var/is_loaded = FALSE

Expand Down Expand Up @@ -315,21 +315,21 @@


/datum/controller/configuration/proc/LoadChatFilter()
var/list/in_character_filter = list()
var/list/word_filter = list()

if(!fexists("[directory]/in_character_filter.txt"))
if(!fexists("[directory]/word_filter.txt"))
return

log_config("Loading config file in_character_filter.txt...")
log_config("Loading config file word_filter.txt...")

for(var/line in file2list("[directory]/in_character_filter.txt"))
for(var/line in file2list("[directory]/word_filter.txt"))
if(!line)
continue
if(findtextEx(line,"#",1,2))
continue
in_character_filter += REGEX_QUOTE(line)
word_filter += REGEX_QUOTE(line)

ic_filter_regex = length(in_character_filter) ? regex("\\b([jointext(in_character_filter, "|")])\\b", "i") : null
word_filter_regex = length(word_filter) ? regex("\\b([jointext(word_filter, "|")])\\b", "i") : null

//Message admins when you can.
/datum/controller/configuration/proc/DelayedMessageAdmins(text)
Expand Down
6 changes: 6 additions & 0 deletions code/game/verbs/ooc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
to_chat(src, "Guests may not use OOC.")
return

if(!filter_message(src, msg))
return

msg = trim(strip_html(msg))
if(!msg) return

Expand Down Expand Up @@ -101,6 +104,9 @@
to_chat(src, "Guests may not use LOOC.")
return

if(!filter_message(src, msg))
return

msg = trim(strip_html(msg))
if(!msg) return

Expand Down
3 changes: 3 additions & 0 deletions code/modules/mob/dead/observer/say.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
if (src.client.handle_spam_prevention(message, MUTE_DEADCHAT))
return

if(!filter_message(client, message))
return

. = src.say_dead(message)


Expand Down
21 changes: 21 additions & 0 deletions code/modules/mob/living/say.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ GLOBAL_LIST_INIT(department_radio_keys, list(
/proc/prefix_to_channel(prefix)
return GLOB.department_radio_keys[prefix]

/proc/filter_message(client/user, message)
if(!config.word_filter_regex)
return TRUE

if(config.word_filter_regex.Find(message))
to_chat(user,
html = "\n<font color='red' size='4'><b>-- Word Filter Message --</b></font>",
)
to_chat(user,
type = MESSAGE_TYPE_ADMINPM,
html = "\n<font color='red' size='4'><b>Your message has been automatically filtered due to its contents. Trying to circumvent this filter will get you banned.</b></font>",
)
SEND_SOUND(user, sound('sound/effects/adminhelp_new.ogg'))
log_admin("[user.ckey] triggered the chat filter with the following message: [message].")
return FALSE

return TRUE

///Shows custom speech bubbles for screaming, *warcry etc.
/mob/living/proc/show_speech_bubble(bubble_name, bubble_type = bubble_icon)

Expand All @@ -81,6 +99,9 @@ GLOBAL_LIST_INIT(department_radio_keys, list(

if(SEND_SIGNAL(src, COMSIG_LIVING_SPEAK, message, speaking, verb, alt_name, italics, message_range, speech_sound, sound_vol, nolog, message_mode) & COMPONENT_OVERRIDE_SPEAK) return

if(!filter_message(src, message))
return

message = process_chat_markup(message, list("~", "_"))

for(var/dst=0; dst<=1; dst++) //Will run twice if src has a clone
Expand Down
2 changes: 1 addition & 1 deletion config/example/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ CLIENT_ERROR_VERSION 514
## GITHUB API
#GITHUB_APP_API
#REPO_NAME cmss13
#ORG cmss13-devs
#ORG cmss13-devs
1 change: 1 addition & 0 deletions config/example/word_filter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Words that should be filtered from being said, both IC and OOC, should be included here, one per line. Case insensitive.

0 comments on commit d628fc6

Please sign in to comment.