Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat Filter #6901

Merged
merged 9 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading