forked from ParadiseSS13/Paradise
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Brainrot filter #1225
Merged
Merged
Brainrot filter #1225
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b92dff7
feat: add brainrot filter
Gaxeer 6aee5e4
tweak: reset config back
Gaxeer 9c5e461
tweak: remove trailing new line from `modular_ss220.dme`
Gaxeer eb2523d
tweak: remove redundant log
Gaxeer 98a2754
fix: add `COMSIG_MOB_LOGOUT` signal unregistering in `/datum/element/…
Gaxeer 67cdfba
refactor: move brainrot filter to config and other small tweaks
Gaxeer f154de7
feat: add lib `rust_utils` for regex text replace
Gaxeer 5b7c203
feat: replace `rust_g_ss220` to `rust_utils`
Gaxeer 37cab15
refactor: adjust to linter
Gaxeer de9a97d
fix: update rust-utils fetch CI
Gaxeer 9e77917
feat: update PreCompile.sh
Gaxeer 7563ea6
flower
Legendaxe 77b33e2
feat: add logging for brainrot filter
Gaxeer 515c241
Merge branch 'brainrot-filter' of https://github.com/Gaxeer/Paradise-…
Gaxeer a92f19f
fix: message replace returns!
Gaxeer bbdee5e
Merge branch 'master' of https://github.com/ss220club/Paradise-Remake…
Gaxeer 0b91551
fix: remove runtimes when reregistering signal
Gaxeer aca9014
Merge branch 'master' into brainrot-filter
Legendaxe d2a26d5
Update modular_ss220/speech_filter/code/speech_filter.dm
Gaxeer 4db2537
Merge branch 'master' into brainrot-filter
Legendaxe 27477f9
Merge branch 'master' into brainrot-filter
Furrior 1a7d4e0
Tabs
Furrior 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/datum/modpack/discord_link | ||
/datum/modpack/species_whitelist | ||
name = "Вайтлист на расы" | ||
desc = "Добавление вайтлиста на расы" | ||
author = "legendaxe" |
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/speech_filter.dm" | ||
#include "code/mob.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,14 @@ | ||
/datum/configuration_section/ss220_misc_configuration | ||
/// Whether or not player speech will be filtered | ||
var/enable_speech_filter = FALSE | ||
/// Set of player ckeys that bypass speech filter | ||
var/list/speech_filter_bypass = list() | ||
|
||
/datum/configuration_section/ss220_misc_configuration/load_data(list/data) | ||
. = ..() | ||
CONFIG_LOAD_BOOL(enable_speech_filter, data["enable_speech_filter"]) | ||
|
||
var/list/filter_bypass | ||
CONFIG_LOAD_LIST(filter_bypass, data["speech_filter_bypass"]) | ||
for(var/whitelisted_ckey in filter_bypass) | ||
speech_filter_bypass[ckey(whitelisted_ckey)] = TRUE |
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,66 @@ | ||
#define BRAINROT_FILTER_FILE 'config/speech_filters/brainrot_filter.json' | ||
|
||
/datum/element/speech_filter | ||
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY | ||
|
||
/datum/element/speech_filter/Attach(datum/target) | ||
. = ..() | ||
if(!isliving(target)) | ||
Gaxeer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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)) | ||
RegisterSignal(mob_to_censor, COMSIG_MOB_LOGOUT, PROC_REF(Detach)) | ||
Gaxeer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/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/talker, list/speech_args) | ||
if(!GLOB.configuration.ss220_misc.enable_speech_filter || can_bypass_filter(talker)) | ||
return | ||
|
||
var/message = speech_args[SPEECH_MESSAGE] | ||
if(message[1] == "*") | ||
return | ||
|
||
var/original_message_length = length(message) | ||
if(!original_message_length) | ||
return | ||
|
||
var/regex/brainrot_filter_regex = get_brainrot_filter_regex() | ||
if(!brainrot_filter_regex) | ||
return | ||
|
||
message = replacetext(message, brainrot_filter_regex, "") | ||
if(original_message_length == length(message)) | ||
return | ||
|
||
speech_args[SPEECH_MESSAGE] = trim(message) | ||
addtimer(CALLBACK(talker, TYPE_PROC_REF(/mob, emote), "drool"), 0.3 SECONDS) | ||
to_chat(talker, span_sinister("Почему у меня такой скудный словарный запас? Стоит сходить в библиотеку и прочесть книгу...")) | ||
|
||
/datum/element/speech_filter/proc/get_brainrot_filter_regex() | ||
if(!fexists(BRAINROT_FILTER_FILE)) | ||
return | ||
|
||
var/static/list/filters = json_load(BRAINROT_FILTER_FILE)["brainrot_filter"] | ||
if(!length(filters)) | ||
return list() | ||
|
||
var/static/regex/brainrot_filter | ||
if(!brainrot_filter) | ||
var/list/unique_filters = list() | ||
unique_filters |= filters | ||
brainrot_filter = regex(unique_filters.Join("|"), "ig") | ||
|
||
return brainrot_filter | ||
|
||
/datum/element/speech_filter/proc/can_bypass_filter(mob/mob_to_check) | ||
return mob_to_check.client.ckey in GLOB.configuration.ss220_misc.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.
Может быть