From fb51a5166b71dfb4e88ba1b01506004965d58a69 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 4 Nov 2020 01:34:30 +0100 Subject: [PATCH] [MIRROR] [s] send2adminchat now stops links from embedding. (#1563) * Merge pull request #54757 from Ghommie/Ghommie-tg33 [s] send2adminchat now stops links from embedding. * [s] send2adminchat now stops links from embedding. Co-authored-by: Jordan Brown --- code/__HELPERS/chat.dm | 4 +++- code/_globalvars/regexes.dm | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/code/__HELPERS/chat.dm b/code/__HELPERS/chat.dm index 2f958eeed0f..4d3a8db806f 100644 --- a/code/__HELPERS/chat.dm +++ b/code/__HELPERS/chat.dm @@ -66,7 +66,9 @@ In TGS3 it will always be sent to all connected designated game chats. * category - The category of the mssage. * message - The message to send. */ -/proc/send2adminchat(category, message) +/proc/send2adminchat(category, message, embed_links = FALSE) category = replacetext(replacetext(category, "\proper", ""), "\improper", "") message = replacetext(replacetext(message, "\proper", ""), "\improper", "") + if(!embed_links) + message = GLOB.has_discord_embeddable_links.Replace(message, "<$1>") world.TgsTargetedChatBroadcast("[category] | [message]", TRUE) diff --git a/code/_globalvars/regexes.dm b/code/_globalvars/regexes.dm index bd252b68ce4..73eaab76440 100644 --- a/code/_globalvars/regexes.dm +++ b/code/_globalvars/regexes.dm @@ -5,3 +5,6 @@ GLOBAL_DATUM_INIT(is_website, /regex, regex("http|www.|\[a-z0-9_-]+.(com|org|net GLOBAL_DATUM_INIT(is_email, /regex, regex("\[a-z0-9_-]+@\[a-z0-9_-]+.\[a-z0-9_-]+", "i")) GLOBAL_DATUM_INIT(is_alphanumeric, /regex, regex("\[a-z0-9]+", "i")) GLOBAL_DATUM_INIT(is_punctuation, /regex, regex("\[.!?]+", "i")) + +//finds text strings recognized as links on discord. Mainly used to stop embedding. +GLOBAL_DATUM_INIT(has_discord_embeddable_links, /regex, regex("(https?://\[^\\s|<\]{2,})"))