Swap memos to be Discord pins instead (#1382)

Intent:
If using a Discord bot, make it so that the game is able to pull and process pinned messages in specific discord channels as memos.
This commit is contained in:
skull132
2017-03-19 21:07:29 +02:00
committed by GitHub
parent 2a0353d8f9
commit 9c78f5b4c6
12 changed files with 862 additions and 313 deletions
+51 -4
View File
@@ -58,7 +58,7 @@
var/result = call("ByondPOST.dll", "send_post_request")(arglist(args))
if (!result)
log_debug("ByondPOST: No result returned from external library.")
log_debug("ByondPOST POST: No result returned from external library.")
return -1
var/list/A = params2list(result)
@@ -67,14 +67,61 @@
// Log the proc error. It should be reviewed by coders ASAP.
switch (A["proc"])
if ("1")
log_debug("ByondPOST: Proc error: Too few arguments sent to function.")
log_debug("ByondPOST POST: Proc error: Too few arguments sent to function.")
if ("2")
log_debug("ByondPOST: Proc error: Unable to initialize curl object.")
log_debug("ByondPOST POST: Proc error: Unable to initialize curl object.")
else
log_debug("ByondPOST: Proc error: Unknown error.")
log_debug("ByondPOST POST: Proc error: Unknown error.")
return -1
// Curl oriented errors should leave the HTTP response code at 0, as no request was executed.
// All HTTP oriented errors will definately return a response code other than 0, so prioritize that.
// Fallback is a curl error code (0 - 92).
return text2num(A["http"]) != 0 ? text2num(A["http"]) : text2num(A["curl"])
/*
* A generic proc for sending a header equipped get requests with the aforementioned .DLL files.
* If you're using this without sending custom headers, please stop. Use world.Export() instead.
* Expected arg structure:
* 1st arg - the url
* 2nd - nth arg - individual headers and their values in format: "headername: value"
*
* @return mixed - Returns list if request was successful, integer (specific cURL or HTTP error) if failed.
* -1 indicates proc or library failure.
* 0 - 92 are curl errors, and are usually accompanied by a HTTP response code of 0 (request was never made).
* 100 - 6xx are HTTP response codes. Curl error code should be 0 in this case, but, in case that it is not,
* the HTTP response code is always returned as long as it is not 0.
*
*/
/proc/send_get_request()
if (args.len < 2)
return -1
var/result = call("ByondPOST.dll", "send_get_request")(arglist(args))
if (!result)
log_debug("ByondPOST GET: No result returned from external library.")
return -1
var/list/A
// Try to evaluate it as JSON data (successful request)
try
A = json_decode(result)
return A
catch()
// Nope, we failed. do regular error parsing instead.
A = params2list(result)
if (!isnull(A["proc"]))
switch (A["proc"])
if ("1")
log_debug("ByondPOST GET: Proc error: Too few arguments sent to function.")
if ("2")
log_debug("ByondPOST GET: Proc error: Unable to initialize curl object.")
else
log_debug("ByondPOST GET: Proc error: Unknown error.")
return -1
return text2num(A["http"]) != 0 ? text2num(A["http"]) : text2num(A["curl"])