Skip to content

Commit c50860f

Browse files
Ryll-RyllDebian
authored and
Debian
committed
Adds linking tickets in asay, referencing mob datums in asay, improves asay ref code (#65634)
About The Pull Request Continuing on the work started in #65154 and 61712, this PR expands what asay linking can be used for and improves the code for it. You can now link tickets in asay by saying #[ticket ID] like DaedalusDock#1. This shows the ticket's status and who filed the ahelp. Might remove the ticket filer if it's not really useful. This also fixes an oversight of mine with datum linking, with how mobs and certain other datums (armor datums, landmarks) don't follow the memory address format for their tag values. Datum linking now uses a @[tag] format, so you can link to a mob by saying @mob_702 and such. dreamseeker_2022-03-22_21-51-41.png Why It's Good For The Game More robust admin tools Changelog cl Ryll/Shaps admin: You can now link tickets in asay with #[ticket ID], like DaedalusDock#1 and DaedalusDock#5. admin: asay datum linking now functions by saying '@[datum's tag value]`, whether it's a normal datum (@0x2001169) or a mob (@mob_702) or whatever else. Discord_2022-03-16_23-38-09.png (old pic)
1 parent ef8429e commit c50860f

File tree

5 files changed

+75
-72
lines changed

5 files changed

+75
-72
lines changed

code/__DEFINES/admin.dm

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ GLOBAL_VAR_INIT(ghost_role_flags, (~0))
142142
#define LIGHTNING_BOLT_DAMAGE 75
143143
#define LIGHTNING_BOLT_ELECTROCUTION_ANIMATION_LENGTH 40
144144

145-
/// 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
146-
#define ADMINSAY_PING_UNDERLINE_NAME_INDEX "!underlined_names"
147-
/// for asay datum refs, this is the index in the return list for [/proc/check_memory_refs] that contains the message modified with underlines for the linked datums
148-
#define ADMINSAY_LINK_DATUM_REF "!datum_ref"
145+
/// for [/proc/check_asay_links], if there are any actionable refs in the asay message, this index in the return list contains the new message text to be printed
146+
#define ASAY_LINK_NEW_MESSAGE_INDEX "!asay_new_message"
147+
/// for [/proc/check_asay_links], if there are any admin pings in the asay message, this index in the return list contains a list of admins to ping
148+
#define ASAY_LINK_PINGED_ADMINS_INDEX "!pinged_admins"
149149

150150
/// When passed in as the duration for ban_panel, will make the ban default to permanent
151151
#define BAN_PANEL_PERMANENT "permanent"

code/_globalvars/_regexes.dm

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ GLOBAL_DATUM_INIT(is_email, /regex, regex("\[a-z0-9_-]+@\[a-z0-9_-]+.\[a-z0-9_-]
66
GLOBAL_DATUM_INIT(is_alphanumeric, /regex, regex("\[a-z0-9]+", "i"))
77
GLOBAL_DATUM_INIT(is_punctuation, /regex, regex("\[.!?]+", "i"))
88
GLOBAL_DATUM_INIT(is_color, /regex, regex("^#\[0-9a-fA-F]{6}$"))
9-
GLOBAL_DATUM_INIT(is_memref, /regex, regex("0x\[0-9a-fA-F\]{7,8}"))
109

1110
//finds text strings recognized as links on discord. Mainly used to stop embedding.
1211
GLOBAL_DATUM_INIT(has_discord_embeddable_links, /regex, regex("(https?://\[^\\s|<\]{2,})"))

code/modules/admin/verbs/adminhelp.dm

+58-49
Original file line numberDiff line numberDiff line change
@@ -977,68 +977,77 @@ GLOBAL_DATUM_INIT(admin_help_ui_handler, /datum/admin_help_ui_handler, new)
977977
return potential_hits
978978

979979
/**
980-
* Checks a given message to see if any of the words contain an active admin's ckey with an @ before it
980+
* Checks a given message to see if any of the words are something we want to treat specially, as detailed below.
981981
*
982-
* Returns nothing if no pings are found, otherwise returns an associative list with ckey -> client
983-
* Also modifies msg to underline the pings, then stores them in the key [ADMINSAY_PING_UNDERLINE_NAME_INDEX] for returning
982+
* There are 3 cases where a word is something we want to act on
983+
* 1. Admin pings, like @adminckey. Pings the admin in question, text is not clickable
984+
* 2. Datum refs, like @0x2001169 or @mob_23. Clicking on the link opens up the VV for that datum
985+
* 3. Ticket refs, like #3. Displays the status and ahelper in the link, clicking on it brings up the ticket panel for it.
986+
* Returns a list being used as a tuple. Index ASAY_LINK_NEW_MESSAGE_INDEX contains the new message text (with clickable links and such)
987+
* while index ASAY_LINK_PINGED_ADMINS_INDEX contains a list of pinged admin clients, if there are any.
984988
*
985989
* Arguments:
986990
* * msg - the message being scanned
987991
*/
988-
/proc/check_admin_pings(msg)
989-
//explode the input msg into a list
990-
var/list/msglist = splittext(msg, " ")
991-
var/list/admins_to_ping = list()
992+
/proc/check_asay_links(msg)
993+
var/list/msglist = splittext(msg, " ") //explode the input msg into a list
994+
var/list/pinged_admins = list() // if we ping any admins, store them here so we can ping them after
995+
var/modified = FALSE // did we find anything?
992996

993997
var/i = 0
994998
for(var/word in msglist)
995999
i++
9961000
if(!length(word))
9971001
continue
998-
if(word[1] != "@")
999-
continue
1000-
var/ckey_check = lowertext(copytext(word, 2))
1001-
var/client/client_check = GLOB.directory[ckey_check]
1002-
if(client_check?.holder)
1003-
msglist[i] = "<u>[word]</u>"
1004-
admins_to_ping[ckey_check] = client_check
10051002

1006-
if(length(admins_to_ping))
1007-
admins_to_ping[ADMINSAY_PING_UNDERLINE_NAME_INDEX] = jointext(msglist, " ") // without tuples, we must make do!
1008-
return admins_to_ping
1009-
1010-
/**
1011-
* Checks a given message to see if any of the words contain a memory ref for a datum. Said ref should not have brackets around it
1012-
*
1013-
* Returns nothing if no refs are found, otherwise returns an associative list with ckey -> client
1014-
* Also modifies msg to underline and linkify the [ref] so other admins can click on the address to open the VV entry for said datum
1015-
*
1016-
* Arguments:
1017-
* * msg - the message being scanned
1018-
*/
1019-
/proc/check_memory_refs(msg)
1020-
if(!findtext(msg, GLOB.is_memref))
1021-
return
1022-
1023-
//explode the input msg into a list
1024-
var/list/msglist = splittext(msg, " ")
1025-
var/list/datums_to_ref = list()
1026-
1027-
var/i = 0
1028-
for(var/word in msglist)
1029-
i++
1030-
if(!length(word))
1031-
continue
1032-
var/word_with_brackets = "\[[word]\]" // the actual memory address lookups need the bracket wraps
1033-
var/datum/check_datum = locate(word_with_brackets)
1034-
if(!istype(check_datum))
1035-
continue
1036-
msglist[i] = "<u><a href='?_src_=vars;[HrefToken(TRUE)];Vars=[word_with_brackets]'>[word_with_brackets]</A></u>"
1037-
datums_to_ref[word] = word
1003+
switch(word[1])
1004+
if("@")
1005+
var/stripped_word = ckey(copytext(word, 2))
1006+
1007+
// first we check if it's a ckey of an admin
1008+
var/client/client_check = GLOB.directory[stripped_word]
1009+
if(client_check?.holder)
1010+
msglist[i] = "<u>[word]</u>"
1011+
pinged_admins[stripped_word] = client_check
1012+
modified = TRUE
1013+
continue
1014+
1015+
// then if not, we check if it's a datum ref
1016+
1017+
var/word_with_brackets = "\[[stripped_word]\]" // the actual memory address lookups need the bracket wraps
1018+
var/datum/datum_check = locate(word_with_brackets)
1019+
if(!istype(datum_check))
1020+
continue
1021+
msglist[i] = "<u><a href='?_src_=vars;[HrefToken(TRUE)];Vars=[word_with_brackets]'>[word]</A></u>"
1022+
modified = TRUE
1023+
1024+
if("#") // check if we're linking a ticket
1025+
var/possible_ticket_id = text2num(copytext(word, 2))
1026+
if(!possible_ticket_id)
1027+
continue
1028+
1029+
var/datum/admin_help/ahelp_check = GLOB.ahelp_tickets?.TicketByID(possible_ticket_id)
1030+
if(!ahelp_check)
1031+
continue
1032+
1033+
var/state_word
1034+
switch(ahelp_check.state)
1035+
if(AHELP_ACTIVE)
1036+
state_word = "Active"
1037+
if(AHELP_CLOSED)
1038+
state_word = "Closed"
1039+
if(AHELP_RESOLVED)
1040+
state_word = "Resolved"
1041+
1042+
msglist[i]= "<u><A href='?_src_=holder;[HrefToken()];ahelp=[REF(ahelp_check)];ahelp_action=ticket'>[word] ([state_word] | [ahelp_check.initiator_key_name])</A></u>"
1043+
modified = TRUE
1044+
1045+
if(modified)
1046+
var/list/return_list = list()
1047+
return_list[ASAY_LINK_NEW_MESSAGE_INDEX] = jointext(msglist, " ") // without tuples, we must make do!
1048+
return_list[ASAY_LINK_PINGED_ADMINS_INDEX] = pinged_admins
1049+
return return_list
10381050

1039-
if(length(datums_to_ref))
1040-
datums_to_ref[ADMINSAY_LINK_DATUM_REF] = jointext(msglist, " ") // without tuples, we must make do!
1041-
return datums_to_ref
10421051

10431052
#undef WEBHOOK_URGENT
10441053
#undef WEBHOOK_NONE

code/modules/admin/verbs/adminsay.dm

+12-17
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,18 @@
99
if(!msg)
1010
return
1111

12-
var/list/pinged_admin_clients = check_admin_pings(msg)
13-
if(length(pinged_admin_clients) && pinged_admin_clients[ADMINSAY_PING_UNDERLINE_NAME_INDEX])
14-
msg = pinged_admin_clients[ADMINSAY_PING_UNDERLINE_NAME_INDEX]
15-
pinged_admin_clients -= ADMINSAY_PING_UNDERLINE_NAME_INDEX
16-
17-
for(var/iter_ckey in pinged_admin_clients)
18-
var/client/iter_admin_client = pinged_admin_clients[iter_ckey]
19-
if(!iter_admin_client?.holder)
20-
continue
21-
window_flash(iter_admin_client)
22-
SEND_SOUND(iter_admin_client.mob, sound('sound/misc/asay_ping.ogg'))
23-
24-
25-
var/list/linked_datums = check_memory_refs(msg)
26-
if(length(linked_datums) && linked_datums[ADMINSAY_LINK_DATUM_REF])
27-
msg = linked_datums[ADMINSAY_LINK_DATUM_REF]
28-
linked_datums -= ADMINSAY_LINK_DATUM_REF
12+
if(findtext(msg, "@") || findtext(msg, "#"))
13+
var/list/link_results = check_asay_links(msg)
14+
if(length(link_results))
15+
msg = link_results[ASAY_LINK_NEW_MESSAGE_INDEX]
16+
link_results[ASAY_LINK_NEW_MESSAGE_INDEX] = null
17+
var/list/pinged_admin_clients = link_results[ASAY_LINK_PINGED_ADMINS_INDEX]
18+
for(var/iter_ckey in pinged_admin_clients)
19+
var/client/iter_admin_client = pinged_admin_clients[iter_ckey]
20+
if(!iter_admin_client?.holder)
21+
continue
22+
window_flash(iter_admin_client)
23+
SEND_SOUND(iter_admin_client.mob, sound('sound/misc/asay_ping.ogg'))
2924

3025
mob.log_talk(msg, LOG_ASAY)
3126
msg = keywords_lookup(msg)

code/modules/admin/view_variables/view_variables.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
sprite_text = no_icon? "\[NO ICON\]" : "<img src='vv[hash].png'></td><td>"
4343
var/list/header = islist(D)? list("<b>/list</b>") : D.vv_get_header()
4444

45-
var/ref_line = copytext(refid, 2, -1) // get rid of the brackets
45+
var/ref_line = "@[copytext(refid, 2, -1)]" // get rid of the brackets, add a @ prefix for copy pasting in asay
4646

4747
var/marked_line
4848
if(holder && holder.marked_datum && holder.marked_datum == D)

0 commit comments

Comments
 (0)