mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
Merge branch 'master' into upstream-merge-10400
This commit is contained in:
72
code/modules/webhooks/_webhook.dm
Normal file
72
code/modules/webhooks/_webhook.dm
Normal file
@@ -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)
|
||||
13
code/modules/webhooks/webhook_ahelp2discord.dm
Normal file
13
code/modules/webhooks/webhook_ahelp2discord.dm
Normal file
@@ -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(GLOB.admins) && ..() // VOREStation Edit - GLOB admins
|
||||
11
code/modules/webhooks/webhook_custom_event.dm
Normal file
11
code/modules/webhooks/webhook_custom_event.dm
Normal file
@@ -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
|
||||
))
|
||||
10
code/modules/webhooks/webhook_fax2discord.dm
Normal file
10
code/modules/webhooks/webhook_fax2discord.dm
Normal file
@@ -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
|
||||
))
|
||||
26
code/modules/webhooks/webhook_roundend.dm
Normal file
26
code/modules/webhooks/webhook_roundend.dm
Normal file
@@ -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
|
||||
))
|
||||
17
code/modules/webhooks/webhook_roundprep.dm
Normal file
17
code/modules/webhooks/webhook_roundprep.dm
Normal file
@@ -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
|
||||
))
|
||||
@@ -13,4 +13,4 @@
|
||||
"title" = "Round has started.",
|
||||
"description" = desc,
|
||||
"color" = COLOR_WEBHOOK_DEFAULT
|
||||
))
|
||||
))
|
||||
Reference in New Issue
Block a user