diff --git a/code/controllers/configuration/sections/discord_configuration.dm b/code/controllers/configuration/sections/discord_configuration.dm index 3d51c92aa42..4f34a753707 100644 --- a/code/controllers/configuration/sections/discord_configuration.dm +++ b/code/controllers/configuration/sections/discord_configuration.dm @@ -7,6 +7,8 @@ var/forward_all_ahelps = TRUE /// Admin role to ping if no admins are online. Disables if empty string var/admin_role_id = "" + /// Mentor role to ping if no mentors are online. Disables if empty string + var/mentor_role_id = "" /// List of all URLs for the main webhooks var/list/main_webhook_urls = list() /// List of all URLs for the admin webhooks @@ -21,6 +23,7 @@ CONFIG_LOAD_BOOL(webhooks_enabled, data["enable_discord_webhooks"]) CONFIG_LOAD_BOOL(forward_all_ahelps, data["forward_all_ahelps"]) CONFIG_LOAD_STR(admin_role_id, data["admin_role_id"]) + CONFIG_LOAD_STR(mentor_role_id, data["mentor_role_id"]) CONFIG_LOAD_LIST(main_webhook_urls, data["main_webhook_urls"]) CONFIG_LOAD_LIST(mentor_webhook_urls, data["mentor_webhook_urls"]) CONFIG_LOAD_LIST(admin_webhook_urls, data["admin_webhook_urls"]) diff --git a/code/controllers/subsystem/discord.dm b/code/controllers/subsystem/discord.dm index 11a2a481073..f3d42a94b51 100644 --- a/code/controllers/subsystem/discord.dm +++ b/code/controllers/subsystem/discord.dm @@ -5,6 +5,8 @@ SUBSYSTEM_DEF(discord) var/enabled = FALSE /// Last time the administrator ping was dropped. This ensures administrators cannot be mass pinged if a large chunk of ahelps go off at once (IE: tesloose) var/last_administration_ping = 0 + /// Last time the mentor ping was dropped. This ensures mentors cannot be mass pinged if a large chunk of mhelps go off at once. + var/last_mentor_ping = 0 /datum/controller/subsystem/discord/Initialize(start_timeofday) if(GLOB.configuration.discord.webhooks_enabled) @@ -75,6 +77,27 @@ SUBSYSTEM_DEF(discord) for(var/url in GLOB.configuration.discord.admin_webhook_urls) SShttp.create_async_request(RUSTG_HTTP_METHOD_POST, url, dwp.serialize2json(), list("content-type" = "application/json")) +/datum/controller/subsystem/discord/proc/send2discord_simple_mentor(content) + var/alerttext + var/list/mentorcounter = staff_countup(R_MENTOR) + var/active_mentors = mentorcounter[1] + var/inactive_mentors = mentorcounter[3] + var/add_ping = FALSE + + if(active_mentors <= 0) + add_ping = TRUE + if(inactive_mentors) + alerttext = "| **ALL MENTORS AFK**" + else + alerttext = "| **NO MENTORS ONLINE**" + + var/message = "[content] [alerttext][add_ping ? handle_mentor_ping() : ""]" + + var/datum/discord_webhook_payload/dwp = new() + dwp.webhook_content = message + for(var/url in GLOB.configuration.discord.mentor_webhook_urls) + SShttp.create_async_request(RUSTG_HTTP_METHOD_POST, url, dwp.serialize2json(), list("content-type" = "application/json")) + // Helper to make administrator ping easier /datum/controller/subsystem/discord/proc/handle_administrator_ping() // Check if a role is even set @@ -86,3 +109,13 @@ SUBSYSTEM_DEF(discord) return "<@&[GLOB.configuration.discord.admin_role_id]>" return "" + +/datum/controller/subsystem/discord/proc/handle_mentor_ping() + if(GLOB.configuration.discord.mentor_role_id) + if(last_mentor_ping > world.time) + return " *(Role pinged recently)*" + + last_mentor_ping = world.time + 60 SECONDS + return " <@&[GLOB.configuration.discord.mentor_role_id]>" + + return "" diff --git a/code/modules/admin/verbs/adminhelp.dm b/code/modules/admin/verbs/adminhelp.dm index 3db301985ed..939bfd10f54 100644 --- a/code/modules/admin/verbs/adminhelp.dm +++ b/code/modules/admin/verbs/adminhelp.dm @@ -47,16 +47,8 @@ GLOBAL_LIST_INIT(adminhelp_ignored_words, list("unknown", "the", "a", "an", "of" SSdiscord.send2discord_simple_noadmins("**\[Adminhelp]** [key_name(src)]: [msg]", check_send_always = TRUE) if("Mentorhelp") - var/alerttext var/list/mentorcount = staff_countup(R_MENTOR) var/active_mentors = mentorcount[1] - var/inactive_mentors = mentorcount[3] - - if(active_mentors <= 0) - if(inactive_mentors) - alerttext = " | **ALL MENTORS AFK**" - else - alerttext = " | **NO MENTORS ONLINE**" log_admin("[selected_type]: [key_name(src)]: [msg] - heard by [active_mentors] non-AFK mentors.") - SSdiscord.send2discord_simple(DISCORD_WEBHOOK_MENTOR, "[key_name(src)]: [msg][alerttext]") + SSdiscord.send2discord_simple_mentor("[key_name(src)]: [msg]") diff --git a/config/example/config.toml b/config/example/config.toml index 70ef8d30132..1cff96b2fba 100644 --- a/config/example/config.toml +++ b/config/example/config.toml @@ -182,8 +182,11 @@ admin_webhook_urls = [ "https://admin.webhook.two" ] # Role ID for the admin role on the discord. Set to "" to disable. -# THIS MUST BE A STRING. BYOND DOESNT LIKE NUMBERS THIS BIG +# THESE MUST BOTH BE STRINGS. BYOND DOESNT LIKE NUMBERS THIS BIG admin_role_id = "" +# Role ID for the mentor role on the discord. Set to "" to disable. +mentor_role_id = "" + # Forward all ahelps to the discord? If disabled, ahelps are only forwarded if admins are AFK/Offline forward_all_ahelps = true