mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-19 03:55:11 +01:00
Pingbus changes and improvements (#65625)
Adds new configs for non-urgent ahelps to be sent to a channel when no admins are on. This will include urgent ahelps too. Adds a response message that is sent to discord when an ahelp is responded to in any way Player counts are now sent in the embed.
This commit is contained in:
@@ -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 = "<byond://[world.internet_address]:[world.port]>"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user