diff options
Diffstat (limited to 'discord/the.lua')
-rw-r--r-- | discord/the.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/discord/the.lua b/discord/the.lua new file mode 100644 index 0000000..d3aaf58 --- /dev/null +++ b/discord/the.lua @@ -0,0 +1,24 @@ +local http_request = require'http.request' +local dkjson = require'dkjson' + +local function exec_webhook(url, payload, debug) + local req = http_request.new_from_uri(url) + req.headers:upsert('content-type','application/json') + req.headers:upsert(':method','POST') + req:set_body(dkjson.encode(payload)) + local resp_head, resp_body = assert(req:go()) + local status = resp_head:get':status' + if debug then + resp_head:dump() + print() + print(resp_body:get_body_as_string()) + end + assert(status:sub(1,1) == '2', 'status was '..status..' not 2xx') +end + +return exec_webhook +-- return { grom = function(from,body) print(body) exec_webhook(url, { +-- content=body, +-- username=from, +-- }, true) end } + |