Skip to content

Commit

Permalink
allow discord relay
Browse files Browse the repository at this point in the history
  • Loading branch information
S34NW committed Sep 2, 2024
1 parent 28be62a commit 7f2caf1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 5 deletions.
3 changes: 3 additions & 0 deletions code/__DEFINES/misc_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions code/controllers/configuration/sections/discord_configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()



Expand All @@ -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"])
4 changes: 4 additions & 0 deletions code/datums/discord/discord_manager.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand All @@ -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"))

Expand Down
12 changes: 10 additions & 2 deletions code/modules/admin/verbs/adminsay.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions code/modules/redis/callbacks/dev_callback.dm
Original file line number Diff line number Diff line change
@@ -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, "<span class='dev_channel'>DEV: <small>[data["author"]]@[data["source"]]</small>: [html_encode(data["message"])]</span>")
6 changes: 5 additions & 1 deletion config/example/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions paradise.dme
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 7f2caf1

Please sign in to comment.