From cb65ddcff812bd63c85fa963a070c97d2bd2d45c Mon Sep 17 00:00:00 2001 From: Ryll Ryll <3589655+Ryll-Ryll@users.noreply.github.com> Date: Mon, 27 Sep 2021 13:15:52 -0400 Subject: [PATCH] Adds pinging to asay (#61712) I spend a lot of my time adminning the servers alt tabbed when not much is going on, tabbing back in every 5-10 minutes to see what's happening or when I hear a bwoink. Sometimes I miss out on other admins asking me questions or trying to get my attention, and I'll only realize way later when I'm scrolling back up through the chat logs, if at all. This PR adds the ability to @ other admins in asay by their ckey, which underlines the pinged name, plays a bloop sound (the one when a vote starts) and flashes their window icon if they're not tabbed in. --- code/__DEFINES/admin.dm | 3 +++ code/modules/admin/verbs/adminhelp.dm | 29 +++++++++++++++++++++++++++ code/modules/admin/verbs/adminsay.dm | 12 +++++++++++ 3 files changed, 44 insertions(+) diff --git a/code/__DEFINES/admin.dm b/code/__DEFINES/admin.dm index bf365f2a323..db431d519f5 100644 --- a/code/__DEFINES/admin.dm +++ b/code/__DEFINES/admin.dm @@ -140,3 +140,6 @@ GLOBAL_VAR_INIT(ghost_role_flags, (~0)) #define LIGHTNING_BOLT_DAMAGE 75 #define LIGHTNING_BOLT_ELECTROCUTION_ANIMATION_LENGTH 40 + +/// for asay pings, this is the index in the return list for [/proc/check_admin_pings] that contains the message modified with underlines for the spotted names +#define ADMINSAY_PING_UNDERLINE_NAME_INDEX "!underlined_names" diff --git a/code/modules/admin/verbs/adminhelp.dm b/code/modules/admin/verbs/adminhelp.dm index 7192504d906..cd5b3b10d0a 100644 --- a/code/modules/admin/verbs/adminhelp.dm +++ b/code/modules/admin/verbs/adminhelp.dm @@ -782,3 +782,32 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new) break return potential_hits + +/** + * Checks a given message to see if any of the words contain an active admin's ckey with an @ before it + * + * Returns nothing if no pings are found, otherwise returns an associative list with ckey -> client + * Also modifies msg to underline the pings, then stores them in the key [ADMINSAY_PING_UNDERLINE_NAME_INDEX] for returning + * + * Arguments: + * * msg - the message being scanned + */ +/proc/check_admin_pings(msg) + //explode the input msg into a list + var/list/msglist = splittext(msg, " ") + var/list/admins_to_ping = list() + + var/i = 0 + for(var/word in msglist) + i++ + if(word[1] != "@") + continue + var/ckey_check = lowertext(copytext(word, 2)) + var/client/client_check = GLOB.directory[ckey_check] + if(client_check?.holder) + msglist[i] = "[word]" + admins_to_ping[ckey_check] = client_check + + if(length(admins_to_ping)) + admins_to_ping[ADMINSAY_PING_UNDERLINE_NAME_INDEX] = jointext(msglist, " ") // without tuples, we must make do! + return admins_to_ping diff --git a/code/modules/admin/verbs/adminsay.dm b/code/modules/admin/verbs/adminsay.dm index d92f3f105ae..34ec74f9f57 100644 --- a/code/modules/admin/verbs/adminsay.dm +++ b/code/modules/admin/verbs/adminsay.dm @@ -9,6 +9,18 @@ if(!msg) return + var/list/pinged_admin_clients = check_admin_pings(msg) + if(length(pinged_admin_clients) && pinged_admin_clients[ADMINSAY_PING_UNDERLINE_NAME_INDEX]) + msg = pinged_admin_clients[ADMINSAY_PING_UNDERLINE_NAME_INDEX] + pinged_admin_clients -= ADMINSAY_PING_UNDERLINE_NAME_INDEX + + for(var/iter_ckey in pinged_admin_clients) + var/client/iter_admin_client = pinged_admin_clients[iter_ckey] + if(!iter_admin_client?.holder) + continue + window_flash(iter_admin_client) + SEND_SOUND(iter_admin_client.mob, sound('sound/misc/bloop.ogg')) + mob.log_talk(msg, LOG_ASAY) msg = keywords_lookup(msg) var/asay_color = prefs.read_preference(/datum/preference/color/asay_color)