diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm index c294dbec2a4..e1de336c5ff 100644 --- a/code/controllers/configuration/entries/general.dm +++ b/code/controllers/configuration/entries/general.dm @@ -596,10 +596,15 @@ /datum/config_entry/string/urgent_ahelp_message default = "This ahelp is urgent!" +/datum/config_entry/string/ahelp_message + default = "" + /datum/config_entry/string/urgent_ahelp_user_prompt default = "There are no admins currently on. Do not press the button below if your ahelp is a joke, a request or a question. Use it only for cases of obvious grief." -/datum/config_entry/string/adminhelp_webhook_url +/datum/config_entry/string/urgent_adminhelp_webhook_url + +/datum/config_entry/string/regular_adminhelp_webhook_url /datum/config_entry/string/adminhelp_webhook_pfp diff --git a/code/modules/admin/verbs/adminhelp.dm b/code/modules/admin/verbs/adminhelp.dm index 36349f1a9ed..11be561b9d8 100644 --- a/code/modules/admin/verbs/adminhelp.dm +++ b/code/modules/admin/verbs/adminhelp.dm @@ -159,6 +159,10 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new) /obj/effect/statclick/ticket_list/proc/Action() Click() +#define WEBHOOK_NONE 0 +#define WEBHOOK_URGENT 1 +#define WEBHOOK_NON_URGENT 2 + /** * # Adminhelp Ticket */ @@ -189,6 +193,8 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new) var/static/ticket_counter = 0 /// The list of clients currently responding to the opening ticket before it gets a response var/list/opening_responders + /// Whether this ahelp has sent a webhook or not, and what type + var/webhook_sent = WEBHOOK_NONE /** * Call this on its own to create a ticket, don't manually assign current_ticket @@ -231,62 +237,82 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new) send_message_to_tgs(msg, urgent) GLOB.ahelp_tickets.active_tickets += src +/datum/admin_help/proc/format_embed_discord(message) + var/datum/discord_embed/embed = new() + embed.title = "Ticket #[id]" + embed.description = "" + embed.author = key_name(initiator_ckey) + var/round_state + switch(SSticker.current_state) + if(GAME_STATE_STARTUP, GAME_STATE_PREGAME, GAME_STATE_SETTING_UP) + round_state = "Round has not started" + if(GAME_STATE_PLAYING) + round_state = "Round is ongoing." + if(SSshuttle.emergency.getModeStr()) + round_state += "\n[SSshuttle.emergency.getModeStr()]: [SSshuttle.emergency.getTimerStr()]" + if(SSticker.emergency_reason) + round_state += ", Shuttle call reason: [SSticker.emergency_reason]" + if(GAME_STATE_FINISHED) + round_state = "Round has ended" + var/list/admin_counts = get_admin_counts(R_BAN) + var/stealth_admins = jointext(admin_counts["stealth"], ", ") + var/afk_admins = jointext(admin_counts["afk"], ", ") + var/other_admins = jointext(admin_counts["noflags"], ", ") + var/admin_text = "" + var/player_count = "**Total**: [length(GLOB.clients)], **Living**: [length(GLOB.alive_player_list)], **Dead**: [length(GLOB.dead_player_list)], **Observers**: [length(GLOB.current_observers_list)]" + if(stealth_admins) + admin_text += "**Stealthed**: [stealth_admins]\n" + if(afk_admins) + admin_text += "**AFK**: [afk_admins]\n" + if(other_admins) + admin_text += "**Lacks +BAN**: [other_admins]\n" + embed.fields = list( + "CKEY" = initiator_ckey, + "PLAYERS" = player_count, + "ROUND STATE" = round_state, + "ROUND ID" = GLOB.round_id, + "ROUND TIME" = ROUND_TIME, + "MESSAGE" = message, + "ADMINS" = admin_text, + ) + if(CONFIG_GET(string/adminhelp_ahelp_link)) + var/ahelp_link = replacetext(CONFIG_GET(string/adminhelp_ahelp_link), "$RID", GLOB.round_id) + ahelp_link = replacetext(ahelp_link, "$TID", id) + embed.url = ahelp_link + return embed + /datum/admin_help/proc/send_message_to_tgs(message, urgent = FALSE) var/message_to_send = message if(urgent) var/extra_message = CONFIG_GET(string/urgent_ahelp_message) to_chat(initiator, span_boldwarning("Notified admins to prioritize your ticket")) - var/datum/discord_embed/embed = new() - embed.title = "Ticket #[id]" - embed.author = key_name(initiator_ckey) - var/round_state - switch(SSticker.current_state) - if(GAME_STATE_STARTUP, GAME_STATE_PREGAME, GAME_STATE_SETTING_UP) - round_state = "Round has not started" - if(GAME_STATE_PLAYING) - round_state = "Round is ongoing." - if(SSshuttle.emergency.getModeStr()) - round_state += "\n[SSshuttle.emergency.getModeStr()]: [SSshuttle.emergency.getTimerStr()]" - if(SSticker.emergency_reason) - round_state += ", Shuttle call reason: [SSticker.emergency_reason]" - if(GAME_STATE_FINISHED) - round_state = "Round has ended" - var/list/admin_counts = get_admin_counts(R_BAN) - var/stealth_admins = jointext(admin_counts["stealth"], ", ") - var/afk_admins = jointext(admin_counts["afk"], ", ") - var/other_admins = jointext(admin_counts["noflags"], ", ") - var/admin_text = "" - if(stealth_admins) - admin_text += "**Stealthed**: [stealth_admins]\n" - if(afk_admins) - admin_text += "**AFK**: [afk_admins]\n" - if(other_admins) - admin_text += "**Lacks +BAN**: [other_admins]\n" - embed.fields = list( - "CKEY" = initiator_ckey, - "ROUND STATE" = round_state, - "ROUND ID" = GLOB.round_id, - "ROUND TIME" = ROUND_TIME, - "MESSAGE" = message, - "ADMINS" = admin_text, - ) + var/datum/discord_embed/embed = format_embed_discord(message) embed.content = extra_message - if(CONFIG_GET(string/adminhelp_ahelp_link)) - var/ahelp_link = replacetext(CONFIG_GET(string/adminhelp_ahelp_link), "$RID", GLOB.round_id) - ahelp_link = replacetext(ahelp_link, "$TID", id) - embed.url = ahelp_link embed.footer = "This player requested an admin" - send2adminchat_webhook(embed) + send2adminchat_webhook(embed, urgent = TRUE) + webhook_sent = WEBHOOK_URGENT //send it to TGS if nobody is on and tell us how many were on var/admin_number_present = send2tgs_adminless_only(initiator_ckey, "Ticket #[id]: [message_to_send]") log_admin_private("Ticket #[id]: [key_name(initiator)]: [name] - heard by [admin_number_present] non-AFK admins who have +BAN.") if(admin_number_present <= 0) to_chat(initiator, span_notice("No active admins are online, your adminhelp was sent to admins who are available through IRC or Discord."), confidential = TRUE) heard_by_no_admins = TRUE + var/regular_webhook_url = CONFIG_GET(string/regular_adminhelp_webhook_url) + if(regular_webhook_url && (!urgent || regular_webhook_url != CONFIG_GET(string/urgent_adminhelp_webhook_url))) + var/extra_message = CONFIG_GET(string/ahelp_message) + var/datum/discord_embed/embed = format_embed_discord(message) + embed.content = extra_message + embed.footer = "This player sent an ahelp when no admins are available [urgent? "and also requested an admin": ""]" + send2adminchat_webhook(embed, urgent = FALSE) + webhook_sent = WEBHOOK_NON_URGENT -/proc/send2adminchat_webhook(message_or_embed) - if(!CONFIG_GET(string/adminhelp_webhook_url)) +/proc/send2adminchat_webhook(message_or_embed, urgent) + var/webhook = CONFIG_GET(string/urgent_adminhelp_webhook_url) + if(!urgent) + webhook = CONFIG_GET(string/regular_adminhelp_webhook_url) + + if(!webhook) return var/list/webhook_info = list() if(istext(message_or_embed)) @@ -307,7 +333,7 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new) var/list/headers = list() headers["Content-Type"] = "application/json" var/datum/http_request/request = new() - request.prepare(RUSTG_HTTP_METHOD_POST, CONFIG_GET(string/adminhelp_webhook_url), json_encode(webhook_info), headers, "tmp/response.json") + request.prepare(RUSTG_HTTP_METHOD_POST, webhook, json_encode(webhook_info), headers, "tmp/response.json") request.begin_async() /datum/admin_help/Destroy() @@ -565,6 +591,19 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new) //Forwarded action from admin/Topic /datum/admin_help/proc/Action(action) testing("Ahelp action: [action]") + if(webhook_sent != WEBHOOK_NONE) + var/datum/discord_embed/embed = new() + embed.title = "Ticket #[id]" + if(CONFIG_GET(string/adminhelp_ahelp_link)) + var/ahelp_link = replacetext(CONFIG_GET(string/adminhelp_ahelp_link), "$RID", GLOB.round_id) + ahelp_link = replacetext(ahelp_link, "$TID", id) + embed.url = ahelp_link + embed.description = "[key_name(usr)] has sent an action to this ticket. Action ID: [action]" + if(webhook_sent == WEBHOOK_URGENT) + send2adminchat_webhook(embed, urgent = TRUE) + if(webhook_sent == WEBHOOK_NON_URGENT || CONFIG_GET(string/regular_adminhelp_webhook_url) != CONFIG_GET(string/urgent_adminhelp_webhook_url)) + send2adminchat_webhook(embed, urgent = FALSE) + webhook_sent = WEBHOOK_NONE switch(action) if("ticket") TicketPanel() @@ -635,7 +674,7 @@ GLOBAL_DATUM_INIT(admin_help_ui_handler, /datum/admin_help_ui_handler, new) . = list() .["bannedFromUrgentAhelp"] = is_banned_from(user.ckey, "Urgent Adminhelp") .["urgentAhelpPromptMessage"] = CONFIG_GET(string/urgent_ahelp_user_prompt) - var/webhook_url = CONFIG_GET(string/adminhelp_webhook_url) + var/webhook_url = CONFIG_GET(string/urgent_adminhelp_webhook_url) if(webhook_url) .["urgentAhelpEnabled"] = TRUE @@ -1000,3 +1039,7 @@ GLOBAL_DATUM_INIT(admin_help_ui_handler, /datum/admin_help_ui_handler, new) if(length(datums_to_ref)) datums_to_ref[ADMINSAY_LINK_DATUM_REF] = jointext(msglist, " ") // without tuples, we must make do! return datums_to_ref + +#undef WEBHOOK_URGENT +#undef WEBHOOK_NONE +#undef WEBHOOK_NON_URGENT diff --git a/config/config.txt b/config/config.txt index 2b35bf6d970..c07e77652db 100644 --- a/config/config.txt +++ b/config/config.txt @@ -564,13 +564,19 @@ DEFAULT_VIEW_SQUARE 15x15 ## The URL to the webhook for adminhelps to relay the urgent ahelp message to ## If not set, will disable urgent ahelps. -#ADMINHELP_WEBHOOK_URL +#URGENT_ADMINHELP_WEBHOOK_URL + +## See above, but for non-urgent ahelps +#REGULAR_ADMINHELP_WEBHOOK_URL ## The urgent ahelp cooldown for a given player if they're alone on a server and need to send an urgent ahelp. URGENT_AHELP_COOLDOWN 300 ## The message that is sent to the discord if an urgent ahelp is sent. Useful for sending a role ping. -#URGENT_AHELP_MESSAGE Ban ban ban ban +#URGENT_AHELP_MESSAGE + +## See above, but for non-urgent ahelps. +#AHELP_MESSAGE ## The message that the player receives whenever prompted whether they want to send an urgent ahelp or not. #URGENT_AHELP_USER_PROMPT This'll ping the admins!