Adds a discord ping for mhelps if there aren't any mentors online (#15533)

* V1

* send2discord_simple_nomentors() proc

* Oh and this too

* Proc name

* Warning comment

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>

* Mentor logout notification message

Adding it in this PR since it's related

* Actually on second thought, this should definitely be its own PR instead

This reverts commit 1e93624c8b.

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
This commit is contained in:
SabreML
2021-10-11 10:05:18 +01:00
committed by GitHub
co-authored by AffectedArc07
parent 01ca06aa13
commit 3935be5808
4 changed files with 41 additions and 10 deletions
@@ -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"])
+33
View File
@@ -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 ""
+1 -9
View File
@@ -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]")