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 5 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
7 changes: 6 additions & 1 deletion config/example/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ external_tos_handler = false
# Path to the map datum to load, overriding the defaults and `data/next_map.txt`.
# Do not use in production.
# Comment out to disable.
#override_map = "/datum/map/test_tiny"
# override_map = "/datum/map/test_tiny"
Gaxeer marked this conversation as resolved.
Show resolved Hide resolved
# Regional servers.
# This is not for separate DD instances per region, but if you have a geo-routing setup deployed to optimise routing for players
# I am 99.9% certain you will never need to fill this out
Expand Down Expand Up @@ -949,6 +949,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
1 change: 1 addition & 0 deletions modular_ss220/modular_ss220.dme
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#include "species_whitelist/_species_whitelist.dme"
#include "antagonists/_antagonists.dme"
#include "uplink_items/_uplink_items.dme"
#include "speech_filter/_speech_filter.dme"

// --- PRIME --- //
// #define MODPACK_MAIN_ONLY
Expand Down
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/discord_link
Gaxeer marked this conversation as resolved.
Show resolved Hide resolved
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/speech_filter.dm"
#include "code/mob.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/Login()
. = ..()
AddElement(/datum/element/speech_filter, src)
53 changes: 53 additions & 0 deletions modular_ss220/speech_filter/code/speech_filter.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/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)
var/regex/brainrot_filter_regex = get_brainrot_filter_regex()
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()
var/static/list/filters = strings("brainrot_filter.json", "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
3 changes: 3 additions & 0 deletions strings/brainrot_filter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"brainrot_filter": []
}
Loading