mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
[MIRROR] Ports Nebula's Discord Webhook Integration
This commit is contained in:
@@ -855,4 +855,15 @@ proc/dd_sortedTextList(list/incoming)
|
||||
result += pick(shifts)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
var/global/list/json_cache = list()
|
||||
/proc/cached_json_decode(var/json_to_decode)
|
||||
if(!json_to_decode || !length(json_to_decode))
|
||||
return list()
|
||||
try
|
||||
if(isnull(global.json_cache[json_to_decode]))
|
||||
global.json_cache[json_to_decode] = json_decode(json_to_decode)
|
||||
. = global.json_cache[json_to_decode]
|
||||
catch(var/exception/e)
|
||||
log_error("Exception during JSON decoding ([json_to_decode]): [e]")
|
||||
return list()
|
||||
@@ -509,3 +509,23 @@ proc/TextPreview(var/string,var/len=40)
|
||||
var/charcount = count - length_char(text)
|
||||
var/list/chars_to_add[max(charcount + 1, 0)]
|
||||
return text + jointext(chars_to_add, char)
|
||||
|
||||
//Readds quotes and apostrophes to HTML-encoded strings
|
||||
/proc/readd_quotes(var/t)
|
||||
var/list/repl_chars = list(""" = "\"","'" = "'")
|
||||
for(var/char in repl_chars)
|
||||
var/index = findtext(t, char)
|
||||
while(index)
|
||||
t = copytext(t, 1, index) + repl_chars[char] + copytext(t, index+5)
|
||||
index = findtext(t, char)
|
||||
return t
|
||||
|
||||
// Rips out paper HTML but tries to keep it semi-readable.
|
||||
/proc/paper_html_to_plaintext(paper_text)
|
||||
paper_text = replacetext(paper_text, "<hr>", "-----")
|
||||
paper_text = replacetext(paper_text, "<li>", "- ") // This makes ordered lists turn into unordered but fixing that is too much effort.
|
||||
paper_text = replacetext(paper_text, "</li>", "\n")
|
||||
paper_text = replacetext(paper_text, "<p>", "\n")
|
||||
paper_text = replacetext(paper_text, "<br>", "\n")
|
||||
paper_text = strip_html_properly(paper_text) // Get rid of everything else entirely.
|
||||
return paper_text
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
//Readds quotes and apostrophes to HTML-encoded strings
|
||||
/proc/readd_quotes(var/t)
|
||||
var/list/repl_chars = list(""" = "\"","'" = "'")
|
||||
for(var/char in repl_chars)
|
||||
var/index = findtext(t, char)
|
||||
while(index)
|
||||
t = copytext(t, 1, index) + repl_chars[char] + copytext(t, index+5)
|
||||
index = findtext(t, char)
|
||||
return t
|
||||
@@ -397,3 +397,17 @@
|
||||
return /datum
|
||||
|
||||
return text2path(copytext(string_type, 1, last_slash))
|
||||
|
||||
//checks if a file exists and contains text
|
||||
//returns text as a string if these conditions are met
|
||||
/proc/safe_file2text(filename, error_on_invalid_return = TRUE)
|
||||
try
|
||||
if(fexists(filename))
|
||||
. = file2text(filename)
|
||||
if(!. && error_on_invalid_return)
|
||||
error("File empty ([filename])")
|
||||
else if(error_on_invalid_return)
|
||||
error("File not found ([filename])")
|
||||
catch(var/exception/E)
|
||||
if(error_on_invalid_return)
|
||||
error("Exception when loading file as string: [E]")
|
||||
Reference in New Issue
Block a user