From 63c29b58c002d351bbccefb603c34e2e194acf71 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 26 Dec 2022 02:59:35 +0100 Subject: [PATCH] [MIRROR] Implements Cooldown On Uploading Books to Newscaster [MDB IGNORE] (#18337) * Implements Cooldown On Uploading Books to Newscaster (#72112) ## About The Pull Request Hey there, Pretty much on the tin. We implement a cooldown on the backend for a set amount of time to prevent people spamming the newscaster channel with a shitload of books (rather than have absolutely no safeguards against it), and then pipe information to the UI for user feedback. ## Why It's Good For The Game Fixes #71290 In case you weren't already aware, letting users absolutely wreck the shit out of player's chat via newscaster spam (all newscasters forcesay a message when something's uploaded to it) as well as just fill the shit up of a channel with various vulgarities isn't a really good thing. ## Changelog :cl: fix: To prevent spam, there is now a cooldown on being able to upload assorted books into the newscaster's channel feed. /:cl: Let me know if the cooldown seems too long, not hard to change. * Implements Cooldown On Uploading Books to Newscaster Co-authored-by: san7890 --- code/modules/library/lib_machines.dm | 12 ++++++++++++ .../tgui/interfaces/LibraryConsole.js | 19 +++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/code/modules/library/lib_machines.dm b/code/modules/library/lib_machines.dm index 2925701ae87..cb459023e9e 100644 --- a/code/modules/library/lib_machines.dm +++ b/code/modules/library/lib_machines.dm @@ -248,6 +248,7 @@ var/duedate #define PRINTER_COOLDOWN (6 SECONDS) +#define NEWSCASTER_COOLDOWN (10 SECONDS) #define LIBRARY_NEWSFEED "Nanotrasen Book Club" //The different states the computer can be in, only send the info we need yeah? #define LIBRARY_INVENTORY 1 @@ -307,6 +308,8 @@ var/datum/weakref/scanner ///Our cooldown on using the printer COOLDOWN_DECLARE(printer_cooldown) + ///Our cooldown on publishing books to the newscaster's "book club" channel + COOLDOWN_DECLARE(newscaster_cooldown) /obj/machinery/computer/libraryconsole/bookmanagement/Initialize(mapload) . = ..() @@ -374,6 +377,10 @@ var/obj/machinery/libraryscanner/scan = get_scanner() data["has_scanner"] = !!(scan) data["has_cache"] = !!(scan?.cache) + + data["cooldown_string"] = "[DisplayTimeText(COOLDOWN_TIMELEFT(src, newscaster_cooldown))]" + data["active_newscaster_cooldown"] = COOLDOWN_FINISHED(src, newscaster_cooldown) + if(scan?.cache) data["cache_title"] = scan.cache.get_title() data["cache_author"] = scan.cache.get_author() @@ -480,6 +487,10 @@ INVOKE_ASYNC(src, PROC_REF(upload_from_scanner), upload_category) return TRUE if("news_post") + // We grey out the button UI-side, but let's just be safe to guard against spammy spammers. + if(!COOLDOWN_FINISHED(src, newscaster_cooldown)) + say("Not enough time has passed since the last news post. Please wait.") + return if(!GLOB.news_network) say("No news network found on station. Aborting.") var/channelexists = FALSE @@ -496,6 +507,7 @@ return GLOB.news_network.submit_article(scan.cache.content, "[scan.cache.author]: [scan.cache.title]", LIBRARY_NEWSFEED, null) say("Upload complete. Your uploaded title is now available on station newscasters.") + COOLDOWN_START(src, newscaster_cooldown, NEWSCASTER_COOLDOWN) return TRUE if("print_book") var/id = params["book_id"] diff --git a/tgui/packages/tgui/interfaces/LibraryConsole.js b/tgui/packages/tgui/interfaces/LibraryConsole.js index 85fc8a96e4c..c376efaf904 100644 --- a/tgui/packages/tgui/interfaces/LibraryConsole.js +++ b/tgui/packages/tgui/interfaces/LibraryConsole.js @@ -483,12 +483,14 @@ export const SearchAndDisplay = (props, context) => { export const Upload = (props, context) => { const { act, data } = useBackend(context); const { - can_db_request, - has_scanner, - has_cache, - cache_title, + active_newscaster_cooldown, cache_author, cache_content, + cache_title, + can_db_request, + has_cache, + has_scanner, + cooldown_string, } = data; const [uploadToDB, setUploadToDB] = useLocalState(context, 'UploadDB', false); if (!has_scanner) { @@ -571,7 +573,16 @@ export const Upload = (props, context) => {