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

Brainrot filter #1225

Merged
merged 22 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b92dff7
feat: add brainrot filter
Gaxeer May 13, 2024
6aee5e4
tweak: reset config back
Gaxeer May 13, 2024
9c5e461
tweak: remove trailing new line from `modular_ss220.dme`
Gaxeer May 13, 2024
eb2523d
tweak: remove redundant log
Gaxeer May 13, 2024
98a2754
fix: add `COMSIG_MOB_LOGOUT` signal unregistering in `/datum/element/…
Gaxeer May 13, 2024
67cdfba
refactor: move brainrot filter to config and other small tweaks
Gaxeer May 13, 2024
f154de7
feat: add lib `rust_utils` for regex text replace
Gaxeer May 14, 2024
5b7c203
feat: replace `rust_g_ss220` to `rust_utils`
Gaxeer May 14, 2024
37cab15
refactor: adjust to linter
Gaxeer May 14, 2024
de9a97d
fix: update rust-utils fetch CI
Gaxeer May 14, 2024
9e77917
feat: update PreCompile.sh
Gaxeer May 14, 2024
7563ea6
flower
Legendaxe May 15, 2024
77b33e2
feat: add logging for brainrot filter
Gaxeer May 16, 2024
515c241
Merge branch 'brainrot-filter' of https://github.com/Gaxeer/Paradise-…
Gaxeer May 16, 2024
a92f19f
fix: message replace returns!
Gaxeer May 16, 2024
bbdee5e
Merge branch 'master' of https://github.com/ss220club/Paradise-Remake…
Gaxeer May 19, 2024
0b91551
fix: remove runtimes when reregistering signal
Gaxeer May 22, 2024
aca9014
Merge branch 'master' into brainrot-filter
Legendaxe Jun 24, 2024
d2a26d5
Update modular_ss220/speech_filter/code/speech_filter.dm
Gaxeer Jul 9, 2024
4db2537
Merge branch 'master' into brainrot-filter
Legendaxe Jul 30, 2024
27477f9
Merge branch 'master' into brainrot-filter
Furrior Sep 1, 2024
1a7d4e0
Tabs
Furrior Sep 1, 2024
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
5 changes: 5 additions & 0 deletions config/example/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,11 @@ ffmpeg_cpuaffinity = ""
force_discord_verification = false
# Respawn delay in minutes before one may respawn as a crew member
respawn_delay = 20
# Enable speech filter for players.
# If enabled, some words will be removed from player's messages.
enable_speech_filter = false
# List of ckeys, that bypass speech filter.
speech_filter_bypass = []
Comment on lines +981 to +985
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно стоит добавить проверку по рангу

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может быть


################################################################

Expand Down
3 changes: 3 additions & 0 deletions config/speech_filters/brainrot_filter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"brainrot_filter": []
}
Binary file added librust_utils.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions modular_ss220/_rust_utils/_rust_utils.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/datum/modpack/rust_utils
name = "Rust Utils"
desc = "Набор утилит на rust"
author = "furior, gaxeer"
3 changes: 3 additions & 0 deletions modular_ss220/_rust_utils/_rust_utils.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "_rust_utils.dm"

#include "code/rust_utils.dm"
28 changes: 28 additions & 0 deletions modular_ss220/_rust_utils/code/rust_utils.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef RUST_UTILS

/* This comment bypasses grep checks */ /var/__rust_utils

/proc/__detect_rust_utils()
if(world.system_type == UNIX)
if(fexists("./librust_utils.so"))
// No need for LD_LIBRARY_PATH badness.
return __rust_utils = "./librust_utils.so"
else
// It's not in the current directory, so try others
return __rust_utils = "librust_utils.so"
else
return __rust_utils = "librust_utils"

#define RUST_UTILS (__rust_utils || __detect_rust_utils())
#endif

/// Gets the version of rust_utils
/proc/rust_utils_get_version() return RUSTG_CALL(RUST_UTILS, "get_version")()

#define rustutils_file_write_b64decode(text, fname) RUSTG_CALL(RUST_UTILS, "file_write")(text, fname, "true")

#define rustutils_regex_replace(text, re, re_params, replacement) RUSTG_CALL(RUST_UTILS, "regex_replace")(text, re, re_params, replacement)

#define rustutils_cyrillic_to_latin(text) RUSTG_CALL(RUST_UTILS, "cyrillic_to_latin")("[text]")
#define rustutils_latin_to_cyrillic(text) RUSTG_CALL(RUST_UTILS, "latin_to_cyrillic")("[text]")

3 changes: 3 additions & 0 deletions modular_ss220/modular_ss220.dme
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// #include "example/_example.dme"

// --- MAINTENANCE --- //
#include "_rust_utils/_rust_utils.dme"
#include "_components/_components.dme"
#include "_defines220/_defines220.dme"
#include "_signals220/_signals220.dme"
Expand Down Expand Up @@ -81,7 +82,9 @@
#include "antagonists/_antagonists.dme"
#include "uplink_items/_uplink_items.dme"
#include "shuttles/_shuttles.dme"
#include "speech_filter/_speech_filter.dme"
#include "redis220/_redis220.dme"

// --- PRIME --- //
// #define MODPACK_MAIN_ONLY
// Чтобы отключить модпаки прайма, нужно добавиту строку выше в code/__DEFINES/_ss220.dm.
Expand Down
2 changes: 1 addition & 1 deletion modular_ss220/species_whitelist/_species_whitelist.dm
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"
4 changes: 4 additions & 0 deletions modular_ss220/speech_filter/_speech_filter.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/datum/modpack/speech_filter
name = "Фильтр речи"
desc = "Фильтрация речи игроков"
author = "gaxeer"
5 changes: 5 additions & 0 deletions modular_ss220/speech_filter/_speech_filter.dme
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"
14 changes: 14 additions & 0 deletions modular_ss220/speech_filter/code/configuration.dm
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
3 changes: 3 additions & 0 deletions modular_ss220/speech_filter/code/mob.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/mob/living/Login()
. = ..()
AddElement(/datum/element/speech_filter, src)
73 changes: 73 additions & 0 deletions modular_ss220/speech_filter/code/speech_filter.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#define BRAINROT_FILTER_FILE "config/speech_filters/brainrot_filter.json"

/datum/element/speech_filter
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY
var/static/list/brainrot_notifications = list(
"Почему у меня такой скудный словарный запас? Стоит сходить в библиотеку и прочесть книгу...",
"Что, черт побери, я несу?",
"Я в своём уме? Надо следить за языком.",
"Неужели я не могу подобрать нужных слов? Позор мне..."
)

/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), TRUE)
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(!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(talker, TYPE_PROC_REF(/mob, emote), "drool"), 0.3 SECONDS)
to_chat(talker, span_sinister(pick(brainrot_notifications)))
log_and_message_admins("[key_name(talker)] 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 = json_load(BRAINROT_FILTER_FILE)["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 GLOB.configuration.ss220_misc.speech_filter_bypass

#undef BRAINROT_FILTER_FILE
1 change: 0 additions & 1 deletion modular_ss220/text_to_speech/_tts.dme
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "code/hear.dm"
#include "code/numbers.dm"
#include "code/providers/silero.dm"
#include "code/rust_g_ss220.dm"
#include "code/seeds/base.dm"
#include "code/seeds/silero.dm"
#include "code/sound.dm"
Expand Down
48 changes: 0 additions & 48 deletions modular_ss220/text_to_speech/code/rust_g_ss220.dm

This file was deleted.

4 changes: 2 additions & 2 deletions modular_ss220/text_to_speech/code/tts_subsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ SUBSYSTEM_DEF(tts220)
if(!voice)
return

rustg_ss220_file_write_b64decode(voice, "[filename].ogg")
rustutils_file_write_b64decode(voice, "[filename].ogg")

if(!GLOB.configuration.tts.tts_cache_enabled)
addtimer(CALLBACK(src, PROC_REF(cleanup_tts_file), "[filename].ogg"), 30 SECONDS)
Expand Down Expand Up @@ -557,7 +557,7 @@ SUBSYSTEM_DEF(tts220)
. = replacetext_char(., acronyms, /proc/tts_acronym_replacer)
for(var/job in tts_job_replacements)
. = replacetext_char(., job, tts_job_replacements[job])
. = rustg_ss220_latin_to_cyrillic(.)
. = rustutils_latin_to_cyrillic(.)

var/static/regex/decimals = new(@"-?\d+\.\d+", "g")
. = replacetext_char(., decimals, /proc/dec_in_words)
Expand Down
6 changes: 0 additions & 6 deletions modular_ss220/text_to_speech/code/~undefs/~undefs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
#undef TTS_TRAIT_RATE_FASTER
#undef TTS_TRAIT_RATE_MEDIUM

#undef rustg_ss220_file_write_b64decode

// Text Operations //
#undef rustg_ss220_cyrillic_to_latin
#undef rustg_ss220_latin_to_cyrillic

#undef TTS_CATEGORY_OTHER
#undef TTS_CATEGORY_WARCRAFT3
#undef TTS_CATEGORY_HALFLIFE2
Expand Down
Binary file removed rust_g_ss220.dll
Binary file not shown.
57 changes: 22 additions & 35 deletions tools/tgs_scripts/PreCompile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,20 @@ set -x
#need to switch to game dir for Dockerfile weirdness
original_dir=$PWD
cd "$1"
. dependencies.sh
. _build_dependencies.sh
cd "$original_dir"

git config --global user.name
if [ $? -eq 1 ]
then
git config --global user.name "paradise_tgs_script"
fi

git config --global user.email
if [ $? -eq 1 ]
then
git config --global user.email "[email protected]"
fi

# update rust-g
if [ ! -d "rust-g" ]; then
echo "Cloning rust-g..."
git clone https://github.com/ParadiseSS13/rust-g
cd rust-g
~/.cargo/bin/rustup target add i686-unknown-linux-gnu
echo "Cloning rust-g..."
git clone https://github.com/ParadiseSS13/rust-g
cd rust-g
~/.cargo/bin/rustup target add i686-unknown-linux-gnu
else
echo "Fetching rust-g..."
cd rust-g
git fetch
~/.cargo/bin/rustup target add i686-unknown-linux-gnu
echo "Fetching rust-g..."
cd rust-g
git fetch
~/.cargo/bin/rustup target add i686-unknown-linux-gnu
fi

echo "Deploying rust-g..."
Expand All @@ -43,25 +31,24 @@ git reset --hard "$RUSTG_VERSION"
cd paradise-rust-g
env PKG_CONFIG_ALLOW_CROSS=1 ~/.cargo/bin/cargo build --release --features all --target=i686-unknown-linux-gnu
mv target/i686-unknown-linux-gnu/release/librust_g.so "$1/librust_g.so"
cd ..
cd ../../

if [ ! -d "rust-g-tg" ]; then
echo "Cloning rust-g..."
git clone https://github.com/ss220club/rust-g-tg
cd rust-g-tg
~/.cargo/bin/rustup target add i686-unknown-linux-gnu
if [ ! -d "rust-utils" ]; then
echo "Cloning rust-utils..."
git clone https://github.com/ss220club/rust-utils
cd rust-utils
~/.cargo/bin/rustup target add i686-unknown-linux-gnu
else
echo "Fetching rust-g..."
cd rust-g-tg
git fetch
~/.cargo/bin/rustup target add i686-unknown-linux-gnu
echo "Fetching rust-utils..."
cd rust-utils
git fetch
~/.cargo/bin/rustup target add i686-unknown-linux-gnu
fi

echo "Deploying rust-g ss220..."
echo "Deploying rustutils..."
RUSTFLAGS="-C target-cpu=native"
env PKG_CONFIG_ALLOW_CROSS=1 ~/.cargo/bin/cargo build --release --features all --target=i686-unknown-linux-gnu
rm -f "$original_dir/../GameStaticFiles/librust_g_ss220.so"
mv target/i686-unknown-linux-gnu/release/librust_g.so "$original_dir/../GameStaticFiles/librust_g_ss220.so"
env PKG_CONFIG_ALLOW_CROSS=1 ~/.cargo/bin/cargo build --release --all-features --target=i686-unknown-linux-gnu
mv target/i686-unknown-linux-gnu/release/librust_utils.so "$1/librust_utils.so"
cd ../../

echo "Deploying MILLA..."
Expand Down
Loading
Loading