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 #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 #1 and #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)
This commit is contained in:
Ryll Ryll
2022-03-31 21:54:43 -04:00
committed by GitHub
parent 75de405a0c
commit 111cdf100e
5 changed files with 72 additions and 69 deletions
+55 -46
View File
@@ -977,68 +977,77 @@ GLOBAL_DATUM_INIT(admin_help_ui_handler, /datum/admin_help_ui_handler, new)
return potential_hits
/**
* Checks a given message to see if any of the words contain an active admin's ckey with an @ before it
* Checks a given message to see if any of the words are something we want to treat specially, as detailed below.
*
* 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
* There are 3 cases where a word is something we want to act on
* 1. Admin pings, like @adminckey. Pings the admin in question, text is not clickable
* 2. Datum refs, like @0x2001169 or @mob_23. Clicking on the link opens up the VV for that datum
* 3. Ticket refs, like #3. Displays the status and ahelper in the link, clicking on it brings up the ticket panel for it.
* Returns a list being used as a tuple. Index ASAY_LINK_NEW_MESSAGE_INDEX contains the new message text (with clickable links and such)
* while index ASAY_LINK_PINGED_ADMINS_INDEX contains a list of pinged admin clients, if there are any.
*
* 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()
/proc/check_asay_links(msg)
var/list/msglist = splittext(msg, " ") //explode the input msg into a list
var/list/pinged_admins = list() // if we ping any admins, store them here so we can ping them after
var/modified = FALSE // did we find anything?
var/i = 0
for(var/word in msglist)
i++
if(!length(word))
continue
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] = "<u>[word]</u>"
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
switch(word[1])
if("@")
var/stripped_word = ckey(copytext(word, 2))
/**
* 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
*
* Returns nothing if no refs are found, otherwise returns an associative list with ckey -> client
* 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
*
* Arguments:
* * msg - the message being scanned
*/
/proc/check_memory_refs(msg)
if(!findtext(msg, GLOB.is_memref))
return
// first we check if it's a ckey of an admin
var/client/client_check = GLOB.directory[stripped_word]
if(client_check?.holder)
msglist[i] = "<u>[word]</u>"
pinged_admins[stripped_word] = client_check
modified = TRUE
continue
//explode the input msg into a list
var/list/msglist = splittext(msg, " ")
var/list/datums_to_ref = list()
// then if not, we check if it's a datum ref
var/i = 0
for(var/word in msglist)
i++
if(!length(word))
continue
var/word_with_brackets = "\[[word]\]" // the actual memory address lookups need the bracket wraps
var/datum/check_datum = locate(word_with_brackets)
if(!istype(check_datum))
continue
msglist[i] = "<u><a href='?_src_=vars;[HrefToken(TRUE)];Vars=[word_with_brackets]'>[word_with_brackets]</A></u>"
datums_to_ref[word] = word
var/word_with_brackets = "\[[stripped_word]\]" // the actual memory address lookups need the bracket wraps
var/datum/datum_check = locate(word_with_brackets)
if(!istype(datum_check))
continue
msglist[i] = "<u><a href='?_src_=vars;[HrefToken(TRUE)];Vars=[word_with_brackets]'>[word]</A></u>"
modified = TRUE
if("#") // check if we're linking a ticket
var/possible_ticket_id = text2num(copytext(word, 2))
if(!possible_ticket_id)
continue
var/datum/admin_help/ahelp_check = GLOB.ahelp_tickets?.TicketByID(possible_ticket_id)
if(!ahelp_check)
continue
var/state_word
switch(ahelp_check.state)
if(AHELP_ACTIVE)
state_word = "Active"
if(AHELP_CLOSED)
state_word = "Closed"
if(AHELP_RESOLVED)
state_word = "Resolved"
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>"
modified = TRUE
if(modified)
var/list/return_list = list()
return_list[ASAY_LINK_NEW_MESSAGE_INDEX] = jointext(msglist, " ") // without tuples, we must make do!
return_list[ASAY_LINK_PINGED_ADMINS_INDEX] = pinged_admins
return return_list
if(length(datums_to_ref))
datums_to_ref[ADMINSAY_LINK_DATUM_REF] = jointext(msglist, " ") // without tuples, we must make do!
return datums_to_ref
#undef WEBHOOK_URGENT
#undef WEBHOOK_NONE
+12 -17
View File
@@ -9,23 +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/asay_ping.ogg'))
var/list/linked_datums = check_memory_refs(msg)
if(length(linked_datums) && linked_datums[ADMINSAY_LINK_DATUM_REF])
msg = linked_datums[ADMINSAY_LINK_DATUM_REF]
linked_datums -= ADMINSAY_LINK_DATUM_REF
if(findtext(msg, "@") || findtext(msg, "#"))
var/list/link_results = check_asay_links(msg)
if(length(link_results))
msg = link_results[ASAY_LINK_NEW_MESSAGE_INDEX]
link_results[ASAY_LINK_NEW_MESSAGE_INDEX] = null
var/list/pinged_admin_clients = link_results[ASAY_LINK_PINGED_ADMINS_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/asay_ping.ogg'))
mob.log_talk(msg, LOG_ASAY)
msg = keywords_lookup(msg)
@@ -42,7 +42,7 @@
sprite_text = no_icon? "\[NO ICON\]" : "<img src='vv[hash].png'></td><td>"
var/list/header = islist(D)? list("<b>/list</b>") : D.vv_get_header()
var/ref_line = copytext(refid, 2, -1) // get rid of the brackets
var/ref_line = "@[copytext(refid, 2, -1)]" // get rid of the brackets, add a @ prefix for copy pasting in asay
var/marked_line
if(holder && holder.marked_datum && holder.marked_datum == D)