forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Speech filter #1082
Merged
Merged
Speech filter #1082
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
af19821
speech filter
MiraHell 2e5421a
maybe fix ci
MiraHell 7bb95e3
super safe
MiraHell b81acd9
Merge branch 'master' into speech-filter
MiraHell 8fb9755
cleanup
MiraHell 1598a9c
Великая точка
MiraHell 251df56
Merge branch 'master' into speech-filter
MiraHell 8084d92
CONFIG_GET
MiraHell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"brainrot_filter": [""] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/datum/modpack/speech_filter | ||
name = "Фильтр речи" | ||
desc = "Фильтрация речи игроков." | ||
author = "gaxeer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "_speech_filter.dm" | ||
|
||
#include "code/configuration.dm" | ||
#include "code/mob.dm" | ||
#include "code/speech_filter.dm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/datum/config_entry/flag/enable_speech_filter | ||
|
||
/datum/config_entry/str_list/speech_filter_bypass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/mob/living/Login() | ||
. = ..() | ||
AddElement(/datum/element/speech_filter, src) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#define BRAINROT_FILTER_FILE "config/bandastation/brainrot_filter.json" | ||
|
||
/datum/element/speech_filter | ||
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY | ||
/// what is displayed to the speaker on replace | ||
var/static/list/brainrot_notifications = list( | ||
"Почему у меня такой скудный словарный запас? Стоит сходить в библиотеку и прочесть книгу...", | ||
"Что, черт побери, я несу?", | ||
"Я в своём уме? Надо следить за языком.", | ||
"Неужели я не могу подобрать нужных слов? Позор мне..." | ||
) | ||
|
||
/datum/element/speech_filter/Attach(datum/target) | ||
. = ..() | ||
if(!isliving(target)) | ||
return ELEMENT_INCOMPATIBLE | ||
|
||
var/mob/mob_to_censor = target | ||
if(!mob_to_censor.client) | ||
return ELEMENT_INCOMPATIBLE | ||
|
||
RegisterSignal(mob_to_censor, COMSIG_MOB_SAY, PROC_REF(filter_speech), TRUE) | ||
RegisterSignal(mob_to_censor, COMSIG_MOB_LOGOUT, PROC_REF(Detach), TRUE) | ||
|
||
/datum/element/speech_filter/Detach(datum/source, force) | ||
. = ..() | ||
UnregisterSignal(source, COMSIG_MOB_SAY) | ||
UnregisterSignal(source, COMSIG_MOB_LOGOUT) | ||
|
||
/datum/element/speech_filter/proc/filter_speech(mob/speaker, list/speech_args) | ||
if(!CONFIG_GET(flag/enable_speech_filter) || can_bypass_filter(speaker)) | ||
return | ||
|
||
var/message = speech_args[SPEECH_MESSAGE] | ||
if(!length(message)) | ||
return | ||
|
||
if(message[1] == "*") | ||
return | ||
|
||
var/brainrot_regex = get_brainrot_filter_regex() | ||
if(!brainrot_regex) | ||
return | ||
|
||
var/original_message = copytext(message, 1) | ||
message = rustutils_regex_replace(message, brainrot_regex, "i", "цветочек") | ||
if(original_message == message) | ||
return | ||
|
||
speech_args[SPEECH_MESSAGE] = message | ||
addtimer(CALLBACK(speaker, TYPE_PROC_REF(/mob, emote), "drool"), 0.3 SECONDS) | ||
to_chat(speaker, span_priorityalert(pick(brainrot_notifications))) | ||
message_admins("[ADMIN_LOOKUPFLW(speaker)] has attempted to say forbidden word. His message was: [original_message]") | ||
log_game("[key_name(speaker)] has attempted to say forbidden word. His message was: [original_message]") | ||
|
||
/datum/element/speech_filter/proc/get_brainrot_filter_regex() | ||
if(!fexists(BRAINROT_FILTER_FILE)) | ||
return | ||
|
||
var/static/list/filters | ||
|
||
if(!length(filters)) | ||
var/raw_filter = file2text(BRAINROT_FILTER_FILE) | ||
if(raw_filter) | ||
var/list/parsed_filter = safe_json_decode(raw_filter) | ||
if(isnull(parsed_filter)) | ||
log_config("JSON parsing failure for [BRAINROT_FILTER_FILE]") | ||
else | ||
filters = parsed_filter["brainrot_filter"] | ||
|
||
if(!length(filters)) | ||
return list() | ||
|
||
var/static/brainrot_regex | ||
if(!brainrot_regex) | ||
var/list/unique_filters = list() | ||
unique_filters |= filters | ||
brainrot_regex = unique_filters.Join("|") | ||
|
||
return brainrot_regex | ||
|
||
/datum/element/speech_filter/proc/can_bypass_filter(mob/mob_to_check) | ||
return mob_to_check.client.ckey in CONFIG_GET(str_list/speech_filter_bypass) | ||
|
||
#undef BRAINROT_FILTER_FILE |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У нас на паре так реализовано? Почему не отдельный файл...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
На паре основной конфиг в .toml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно было добавить еще один ключ в
brainrot_filter.json
, но не думаю, что много кому надо обходить фильтр, максимум самим стримерам