From 7f2caf1041bc89ce2b0b624324d52ea8c4115a4b Mon Sep 17 00:00:00 2001 From: S34N <12197162+S34NW@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:17:32 +0100 Subject: [PATCH] allow discord relay --- code/__DEFINES/misc_defines.dm | 3 +++ .../configuration/sections/discord_configuration.dm | 10 ++++++++-- code/datums/discord/discord_manager.dm | 4 ++++ code/modules/admin/verbs/adminsay.dm | 12 ++++++++++-- code/modules/redis/callbacks/dev_callback.dm | 11 +++++++++++ config/example/config.toml | 6 +++++- paradise.dme | 1 + 7 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 code/modules/redis/callbacks/dev_callback.dm diff --git a/code/__DEFINES/misc_defines.dm b/code/__DEFINES/misc_defines.dm index ad1a5a1aa8b5..ff4948d9a80e 100644 --- a/code/__DEFINES/misc_defines.dm +++ b/code/__DEFINES/misc_defines.dm @@ -548,6 +548,9 @@ /// Send to the mentor Discord webhook #define DISCORD_WEBHOOK_MENTOR "MENTOR" +/// Send to the developer Discord webhook +#define DISCORD_WEBHOOK_DEVELOPER "DEVELOPER" + // Hallucination severities #define HALLUCINATE_MINOR 1 #define HALLUCINATE_MODERATE 2 diff --git a/code/controllers/configuration/sections/discord_configuration.dm b/code/controllers/configuration/sections/discord_configuration.dm index 4f34a7537070..7b8d4a318fe5 100644 --- a/code/controllers/configuration/sections/discord_configuration.dm +++ b/code/controllers/configuration/sections/discord_configuration.dm @@ -9,12 +9,16 @@ var/admin_role_id = "" /// Mentor role to ping if no mentors are online. Disables if empty string var/mentor_role_id = "" + /// Developer role in case ping functionality is added. Disables if empty string + var/developer_role_id = "" /// List of all URLs for the main webhooks var/list/main_webhook_urls = list() - /// List of all URLs for the admin webhooks - var/list/mentor_webhook_urls = list() /// List of all URLs for the mentor webhooks + var/list/mentor_webhook_urls = list() + /// List of all URLs for the admin webhooks var/list/admin_webhook_urls = list() + /// List of all URLs for the developer webhooks + var/list/developer_webhook_urls = list() @@ -24,6 +28,8 @@ 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_STR(developer_role_id, data["developer_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"]) + CONFIG_LOAD_LIST(developer_webhook_urls, data["developer_webhook_urls"]) diff --git a/code/datums/discord/discord_manager.dm b/code/datums/discord/discord_manager.dm index 006922315c12..57812759d1cd 100644 --- a/code/datums/discord/discord_manager.dm +++ b/code/datums/discord/discord_manager.dm @@ -18,6 +18,8 @@ GLOBAL_DATUM_INIT(discord_manager, /datum/discord_manager, new()) webhook_urls = GLOB.configuration.discord.main_webhook_urls if(DISCORD_WEBHOOK_MENTOR) webhook_urls = GLOB.configuration.discord.mentor_webhook_urls + if(DISCORD_WEBHOOK_DEVELOPER) + webhook_urls = GLOB.configuration.discord.developer_webhook_urls var/datum/discord_webhook_payload/dwp = new() dwp.webhook_content = "**\[[GLOB.configuration.system.instance_id]]** [content]" @@ -36,6 +38,8 @@ GLOBAL_DATUM_INIT(discord_manager, /datum/discord_manager, new()) webhook_urls = GLOB.configuration.discord.main_webhook_urls if(DISCORD_WEBHOOK_MENTOR) webhook_urls = GLOB.configuration.discord.mentor_webhook_urls + if(DISCORD_WEBHOOK_DEVELOPER) + webhook_urls = GLOB.configuration.discord.developer_webhook_urls for(var/url in webhook_urls) SShttp.create_async_request(RUSTG_HTTP_METHOD_POST, url, dwp.serialize2json(), list("content-type" = "application/json")) diff --git a/code/modules/admin/verbs/adminsay.dm b/code/modules/admin/verbs/adminsay.dm index c992c48b9202..f01ec5578478 100644 --- a/code/modules/admin/verbs/adminsay.dm +++ b/code/modules/admin/verbs/adminsay.dm @@ -58,13 +58,21 @@ return msg = emoji_parse(copytext_char(sanitize(msg), 1, MAX_MESSAGE_LEN)) + + if(!msg) + return + log_devsay(msg, src) var/datum/say/devsay = new(usr.ckey, usr.client.holder.rank, msg, world.timeofday) GLOB.devsays += devsay mob.create_log(OOC_LOG, "DEVSAY: [msg]") - if(!msg) - return + if(SSredis.connected) + var/list/data = list() + data["author"] = usr.ckey + data["source"] = GLOB.configuration.system.instance_id + data["message"] = html_decode(msg) + SSredis.publish("byond.devsay", json_encode(data)) for(var/client/C in GLOB.admins) if(check_rights(R_ADMIN|R_MOD|R_DEV_TEAM, 0, C.mob)) diff --git a/code/modules/redis/callbacks/dev_callback.dm b/code/modules/redis/callbacks/dev_callback.dm new file mode 100644 index 000000000000..ea192d6440dd --- /dev/null +++ b/code/modules/redis/callbacks/dev_callback.dm @@ -0,0 +1,11 @@ +// Relays messages to developer +/datum/redis_callback/developer_in + channel = "byond.devsay" + +/datum/redis_callback/developer_in/on_message(message) + var/list/data = json_decode(message) + if(data["source"] == GLOB.configuration.system.instance_id) // Ignore self messages + return + for(var/client/C in GLOB.admins) + if(check_rights(R_ADMIN|R_DEV_TEAM, FALSE, C.mob)) + to_chat(C, "DEV: [data["author"]]@[data["source"]]: [html_encode(data["message"])]") diff --git a/config/example/config.toml b/config/example/config.toml index defcf2f3d1b4..cf60e2695641 100644 --- a/config/example/config.toml +++ b/config/example/config.toml @@ -214,11 +214,15 @@ mentor_webhook_urls = [ ] # List of all webhook URLs for the admin feed (round alerts, ahelps, etc) admin_webhook_urls = ["https://admin.webhook.one", "https://admin.webhook.two"] +# List of all webhook URLs for the admin feed (devsay relay) +developer_webhook_urls = ["https://developer.webhook.one", "https://developer.webhook.two"] # Role ID for the admin role on the discord. Set to "" to disable. -# THESE MUST BOTH BE STRINGS. BYOND DOESNT LIKE NUMBERS THIS BIG +# THESE MUST BE STRINGS. BYOND DOESNT LIKE NUMBERS THIS BIG admin_role_id = "" # Role ID for the mentor role on the discord. Set to "" to disable. mentor_role_id = "" +# Role ID for the developer role on the discord. Set to "" to disable. +developer_role_id = "" # Forward all ahelps to the discord? If disabled, ahelps are only forwarded if admins are AFK/Offline forward_all_ahelps = true diff --git a/paradise.dme b/paradise.dme index 9fe3bf88a113..50292df1a218 100644 --- a/paradise.dme +++ b/paradise.dme @@ -2699,6 +2699,7 @@ #include "code\modules\redis\redis_callback.dm" #include "code\modules\redis\redis_message.dm" #include "code\modules\redis\callbacks\asay_callback.dm" +#include "code\modules\redis\callbacks\dev_callback.dm" #include "code\modules\redis\callbacks\msay_callback.dm" #include "code\modules\redis\callbacks\server_messages_callback.dm" #include "code\modules\research\circuitprinter.dm"