mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2026-08-28 15:47:38 +01:00
Ports Nebula's Discord Webhook Integration (#8071)
* Ports Nebula's Discord Webhook Integration * Forgot the example .json file.
This commit is contained in:
@@ -1626,6 +1626,19 @@ datum/admins/var/obj/item/weapon/paper/admin/faxreply // var to hold fax replies
|
||||
for(var/client/C in admins)
|
||||
if((R_ADMIN | R_MOD | R_EVENT) & C.holder.rights)
|
||||
to_chat(C, "<span class='log_message'><span class='prefix'>FAX LOG:</span>[key_name_admin(src.owner)] has sent a fax message to [destination.department] (<a href='?_src_=holder;AdminFaxView=\ref[rcvdcopy]'>VIEW</a>)</span>")
|
||||
|
||||
var/plaintext_title = P.sender ? "replied to [key_name(P.sender)]'s fax" : "sent a fax message to [destination.department]"
|
||||
var/fax_text = paper_html_to_plaintext(P.info)
|
||||
log_game(plaintext_title)
|
||||
log_game(fax_text)
|
||||
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_FAX_SENT,
|
||||
list(
|
||||
"name" = "[key_name(owner)] [plaintext_title].",
|
||||
"body" = fax_text
|
||||
)
|
||||
)
|
||||
|
||||
else
|
||||
to_chat(src.owner, "<span class='warning'>Message reply failed.</span>")
|
||||
|
||||
@@ -234,7 +234,9 @@ var/list/admin_verbs_debug = list(
|
||||
/client/proc/admin_give_modifier,
|
||||
/client/proc/simple_DPS,
|
||||
/datum/admins/proc/view_feedback,
|
||||
/client/proc/debug_global_variables
|
||||
/client/proc/debug_global_variables,
|
||||
/client/proc/ping_webhook,
|
||||
/client/proc/reload_webhooks
|
||||
)
|
||||
|
||||
var/list/admin_verbs_paranoid_debug = list(
|
||||
|
||||
@@ -184,6 +184,16 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
|
||||
log_admin("Ticket #[id]: [key_name(initiator)]: [name] - heard by [admin_number_present] non-AFK admins who have +BAN.")
|
||||
if(admin_number_present <= 0)
|
||||
to_chat(C, "<span class='notice'>No active admins are online, your adminhelp was sent to the admin irc.</span>")
|
||||
|
||||
// Also send it to discord since that's the hip cool thing now.
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_AHELP_SENT,
|
||||
list(
|
||||
"name" = "Ticket ([id]) (Game ID: [game_id]) ticket opened.",
|
||||
"body" = "[key_name(initiator)] has opened a ticket. \n[msg]",
|
||||
"color" = COLOR_WEBHOOK_POOR
|
||||
)
|
||||
)
|
||||
|
||||
GLOB.ahelp_tickets.active_tickets += src
|
||||
|
||||
@@ -274,6 +284,14 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
|
||||
feedback_inc("ahelp_reopen")
|
||||
TicketPanel() //can only be done from here, so refresh it
|
||||
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_AHELP_SENT,
|
||||
list(
|
||||
"name" = "Ticket ([id]) (Game ID: [game_id]) reopened.",
|
||||
"body" = "Reopened by [key_name(usr)]."
|
||||
)
|
||||
)
|
||||
|
||||
//private
|
||||
/datum/admin_help/proc/RemoveActive()
|
||||
if(state != AHELP_ACTIVE)
|
||||
@@ -299,6 +317,14 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
|
||||
var/msg = "Ticket [TicketHref("#[id]")] closed by [key_name_admin(usr)]."
|
||||
message_admins(msg)
|
||||
log_admin(msg)
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_AHELP_SENT,
|
||||
list(
|
||||
"name" = "Ticket ([id]) (Game ID: [game_id]) closed.",
|
||||
"body" = "Closed by [key_name(usr)].",
|
||||
"color" = COLOR_WEBHOOK_BAD
|
||||
)
|
||||
)
|
||||
|
||||
//Mark open ticket as resolved/legitimate, returns ahelp verb
|
||||
/datum/admin_help/proc/Resolve(silent = FALSE)
|
||||
@@ -316,6 +342,14 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
|
||||
var/msg = "Ticket [TicketHref("#[id]")] resolved by [key_name_admin(usr)]"
|
||||
message_admins(msg)
|
||||
log_admin(msg)
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_AHELP_SENT,
|
||||
list(
|
||||
"name" = "Ticket ([id]) (Game ID: [game_id]) resolved.",
|
||||
"body" = "Marked as Resolved by [key_name(usr)].",
|
||||
"color" = COLOR_WEBHOOK_GOOD
|
||||
)
|
||||
)
|
||||
|
||||
//Close and return ahelp verb, use if ticket is incoherent
|
||||
/datum/admin_help/proc/Reject(key_name = key_name_admin(usr))
|
||||
@@ -336,6 +370,14 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
|
||||
log_admin(msg)
|
||||
AddInteraction("Rejected by [key_name_admin(usr)].")
|
||||
Close(silent = TRUE)
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_AHELP_SENT,
|
||||
list(
|
||||
"name" = "Ticket ([id]) (Game ID: [game_id]) rejected.",
|
||||
"body" = "Rejected by [key_name(usr)].",
|
||||
"color" = COLOR_WEBHOOK_BAD
|
||||
)
|
||||
)
|
||||
|
||||
//Resolve ticket with IC Issue message
|
||||
/datum/admin_help/proc/ICIssue(key_name = key_name_admin(usr))
|
||||
@@ -355,6 +397,14 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
|
||||
log_admin(msg)
|
||||
AddInteraction("Marked as IC issue by [key_name_admin(usr)]")
|
||||
Resolve(silent = TRUE)
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_AHELP_SENT,
|
||||
list(
|
||||
"name" = "Ticket ([id]) (Game ID: [game_id]) marked as IC issue.",
|
||||
"body" = "Marked as IC Issue by [key_name(usr)].",
|
||||
"color" = COLOR_WEBHOOK_BAD
|
||||
)
|
||||
)
|
||||
|
||||
//Resolve ticket with IC Issue message
|
||||
/datum/admin_help/proc/HandleIssue()
|
||||
@@ -366,11 +416,18 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
|
||||
if(initiator)
|
||||
to_chat(initiator, msg)
|
||||
|
||||
feedback_inc("ahelp_icissue")
|
||||
feedback_inc("ahelp_handling")
|
||||
msg = "Ticket [TicketHref("#[id]")] being handled by [key_name(usr,FALSE,FALSE)]"
|
||||
message_admins(msg)
|
||||
log_admin(msg)
|
||||
AddInteraction("[key_name_admin(usr)] is now handling this ticket.")
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_AHELP_SENT,
|
||||
list(
|
||||
"name" = "Ticket ([id]) (Game ID: [game_id]) being handled.",
|
||||
"body" = "[key_name(usr)] is now handling the ticket."
|
||||
)
|
||||
)
|
||||
|
||||
//Show the ticket panel
|
||||
/datum/admin_help/proc/TicketPanel()
|
||||
|
||||
@@ -24,6 +24,13 @@
|
||||
to_world("<span class='alert'>[custom_event_msg]</span>")
|
||||
to_world("<br>")
|
||||
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_CUSTOM_EVENT,
|
||||
list(
|
||||
"text" = custom_event_msg,
|
||||
)
|
||||
)
|
||||
|
||||
// normal verb for players to view info
|
||||
/client/verb/cmd_view_custom_event()
|
||||
set category = "OOC"
|
||||
|
||||
@@ -210,6 +210,21 @@ var/list/adminfaxes = list() //cache for faxes that have been sent to admins
|
||||
sleep(50)
|
||||
visible_message("[src] beeps, \"Message transmitted successfully.\"")
|
||||
|
||||
// Turns objects into just text.
|
||||
/obj/machinery/photocopier/faxmachine/proc/make_summary(obj/item/sent)
|
||||
if(istype(sent, /obj/item/weapon/paper))
|
||||
var/obj/item/weapon/paper/P = sent
|
||||
return P.info
|
||||
if(istype(sent, /obj/item/weapon/paper_bundle))
|
||||
. = ""
|
||||
var/obj/item/weapon/paper_bundle/B = sent
|
||||
for(var/i in 1 to B.pages.len)
|
||||
var/obj/item/weapon/paper/P = B.pages[i]
|
||||
if(istype(P)) // Photos can show up here too.
|
||||
if(.) // Space out different pages.
|
||||
. += "<br>"
|
||||
. += "PAGE [i] - [P.name]<br>"
|
||||
. += P.info
|
||||
|
||||
/obj/machinery/photocopier/faxmachine/proc/message_admins(var/mob/sender, var/faxname, var/obj/item/sent, var/reply_type, font_colour="#006100")
|
||||
var/msg = "<span class='notice'><b><font color='[font_colour]'>[faxname]: </font>[get_options_bar(sender, 2,1,1)]"
|
||||
@@ -220,3 +235,23 @@ var/list/adminfaxes = list() //cache for faxes that have been sent to admins
|
||||
if(check_rights((R_ADMIN|R_MOD|R_EVENT),0,C))
|
||||
to_chat(C,msg)
|
||||
C << 'sound/machines/printer.ogg'
|
||||
|
||||
// Webhooks don't parse the HTML on the paper, so we gotta strip them out so it's still readable.
|
||||
var/summary = make_summary(sent)
|
||||
summary = paper_html_to_plaintext(summary)
|
||||
|
||||
log_game("Fax to [lowertext(faxname)] was sent by [key_name(sender)].")
|
||||
log_game(summary)
|
||||
|
||||
var/webhook_length_limit = 1900 // The actual limit is a little higher.
|
||||
if(length(summary) > webhook_length_limit)
|
||||
summary = copytext(summary, 1, webhook_length_limit + 1)
|
||||
summary += "\n\[Truncated\]"
|
||||
|
||||
SSwebhooks.send(
|
||||
WEBHOOK_FAX_SENT,
|
||||
list(
|
||||
"name" = "[faxname] '[sent.name]' sent from [key_name(sender)]",
|
||||
"body" = summary
|
||||
)
|
||||
)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/decl/webhook
|
||||
var/id
|
||||
var/list/urls
|
||||
var/list/mentions
|
||||
|
||||
/decl/webhook/proc/get_message(var/list/data)
|
||||
. = list()
|
||||
|
||||
/decl/webhook/proc/http_post(var/target_url, var/payload)
|
||||
if (!target_url)
|
||||
return -1
|
||||
|
||||
var/result = call(HTTP_POST_DLL_LOCATION, "send_post_request")(target_url, payload, json_encode(list("Content-Type" = "application/json")))
|
||||
|
||||
result = cached_json_decode(result)
|
||||
if (result["error_code"])
|
||||
log_debug("byhttp error: [result["error"]] ([result["error_code"]])")
|
||||
return result["error_code"]
|
||||
|
||||
return list(
|
||||
"status_code" = result["status_code"],
|
||||
"body" = result["body"]
|
||||
)
|
||||
|
||||
/decl/webhook/proc/send(var/list/data)
|
||||
var/list/message = get_message(data)
|
||||
if(!length(message))
|
||||
return FALSE
|
||||
|
||||
if(config.disable_webhook_embeds)
|
||||
var/list/embed_content
|
||||
for(var/list/embed in message["embeds"])
|
||||
if(embed["title"])
|
||||
LAZYADD(embed_content, "**[embed["title"]]**")
|
||||
if(embed["description"])
|
||||
LAZYADD(embed_content, embed["description"])
|
||||
if(length(embed_content))
|
||||
if(message["content"])
|
||||
message["content"] = "[message["content"]]\n[jointext(embed_content, "\n")]"
|
||||
else
|
||||
message["content"] = jointext(embed_content, "\n")
|
||||
message -= "embeds"
|
||||
|
||||
. = TRUE
|
||||
for(var/target_url in urls)
|
||||
|
||||
var/url_message = message.Copy()
|
||||
var/list/url_mentions = get_mentions(target_url)
|
||||
if(islist(url_mentions) && length(url_mentions))
|
||||
if(url_message["content"])
|
||||
url_message["content"] = "[jointext(url_mentions, ", ")]: [url_message["content"]]"
|
||||
else
|
||||
url_message["content"] = "[jointext(url_mentions, ", ")]"
|
||||
|
||||
var/list/httpresponse = http_post(target_url, json_encode(url_message))
|
||||
if(!islist(httpresponse))
|
||||
. = FALSE
|
||||
continue
|
||||
switch(httpresponse["status_code"])
|
||||
if (200 to 299)
|
||||
continue
|
||||
if (400 to 599)
|
||||
log_debug("Webhooks: HTTP error code while sending to '[target_url]': [httpresponse["status_code"]]. Data: [httpresponse["body"]].")
|
||||
else
|
||||
log_debug("Webhooks: unknown HTTP code while sending to '[target_url]': [httpresponse["status_code"]]. Data: [httpresponse["body"]].")
|
||||
. = FALSE
|
||||
|
||||
/decl/webhook/proc/get_mentions(var/mentioning_url)
|
||||
. = mentions?.Copy()
|
||||
var/url_mentions = LAZYACCESS(urls, mentioning_url)
|
||||
if(length(url_mentions))
|
||||
LAZYDISTINCTADD(., url_mentions)
|
||||
@@ -0,0 +1,13 @@
|
||||
/decl/webhook/ahelp_sent
|
||||
id = WEBHOOK_AHELP_SENT
|
||||
|
||||
/decl/webhook/ahelp_sent/get_message(var/list/data)
|
||||
.= ..()
|
||||
.["embeds"] = list(list(
|
||||
"title" = "[data["name"]]",
|
||||
"description" = data["body"],
|
||||
"color" = data["color"] || COLOR_WEBHOOK_DEFAULT
|
||||
))
|
||||
|
||||
/decl/webhook/ahelp_sent/get_mentions()
|
||||
. = !length(global.admins) && ..()
|
||||
@@ -0,0 +1,11 @@
|
||||
/decl/webhook/custom_event
|
||||
id = WEBHOOK_CUSTOM_EVENT
|
||||
|
||||
// Data expects a "text" field containing the new custom event text.
|
||||
/decl/webhook/custom_event/get_message(var/list/data)
|
||||
. = ..()
|
||||
.["embeds"] = list(list(
|
||||
"title" = "A custom event is beginning.",
|
||||
"description" = (data && data["text"]) || "undefined",
|
||||
"color" = COLOR_WEBHOOK_DEFAULT
|
||||
))
|
||||
@@ -0,0 +1,10 @@
|
||||
/decl/webhook/fax_sent
|
||||
id = WEBHOOK_FAX_SENT
|
||||
|
||||
/decl/webhook/fax_sent/get_message(var/list/data)
|
||||
.= ..()
|
||||
.["embeds"] = list(list(
|
||||
"title" = "[data["name"]]",
|
||||
"description" = data["body"],
|
||||
"color" = COLOR_WEBHOOK_DEFAULT
|
||||
))
|
||||
@@ -0,0 +1,26 @@
|
||||
/decl/webhook/roundend
|
||||
id = WEBHOOK_ROUNDEND
|
||||
|
||||
// Data expects three numerical fields: "survivors", "escaped", "ghosts", "clients"
|
||||
/decl/webhook/roundend/get_message(var/list/data)
|
||||
. = ..()
|
||||
var/desc = "A round of **[SSticker.mode ? SSticker.mode.name : "Unknown"]** ([game_id]) has ended.\n\n"
|
||||
if(data)
|
||||
var/s_escaped = "Escaped"
|
||||
if(!emergency_shuttle.evac)
|
||||
s_escaped = "Transferred"
|
||||
if(data["survivors"] > 0)
|
||||
desc += "Survivors: **[data["survivors"]]**\n"
|
||||
desc += "[s_escaped]: **[data["escaped"]]**\n"
|
||||
else
|
||||
desc += "There were **no survivors**.\n\n"
|
||||
desc += "Ghosts: **[data["ghosts"]]**\n"
|
||||
desc += "Players: **[data["clients"]]**\n"
|
||||
desc += "Round duration: **[roundduration2text()]**"
|
||||
|
||||
.["embeds"] = list(list(
|
||||
// "title" = global.end_credits_title,
|
||||
"title" = "Round Has Ended",
|
||||
"description" = desc,
|
||||
"color" = COLOR_WEBHOOK_DEFAULT
|
||||
))
|
||||
@@ -0,0 +1,17 @@
|
||||
/decl/webhook/roundprep
|
||||
id = WEBHOOK_ROUNDPREP
|
||||
|
||||
// Data expects "url" and field pointing to the current hosted server and port to connect on.
|
||||
/decl/webhook/roundprep/get_message(var/list/data)
|
||||
. = ..()
|
||||
var/desc = "The server has been started!\n"
|
||||
if(data && data["map"])
|
||||
desc += "Map: **[data["map"]]**\n"
|
||||
if(data && data["url"])
|
||||
desc += "Address: <[data["url"]]>"
|
||||
|
||||
.["embeds"] = list(list(
|
||||
"title" = "New round is being set up.",
|
||||
"description" = desc,
|
||||
"color" = COLOR_WEBHOOK_DEFAULT
|
||||
))
|
||||
@@ -0,0 +1,16 @@
|
||||
/decl/webhook/roundstart
|
||||
id = WEBHOOK_ROUNDSTART
|
||||
|
||||
// Data expects a "url" field pointing to the current hosted server and port to connect on.
|
||||
/decl/webhook/roundstart/get_message(var/list/data)
|
||||
. = ..()
|
||||
var/desc = "Gamemode: **[SSticker.mode.name]**\n"
|
||||
desc += "Players: **[global.player_list.len]**"
|
||||
if(data && data["url"])
|
||||
desc += "\nAddress: <[data["url"]]>"
|
||||
|
||||
.["embeds"] = list(list(
|
||||
"title" = "Round has started.",
|
||||
"description" = desc,
|
||||
"color" = COLOR_WEBHOOK_DEFAULT
|
||||
))
|
||||
Reference in New Issue
Block a user