summaryrefslogtreecommitdiff
path: root/discord.lua
blob: 27e06443ff4735823b32cf7dc1d707759d43845f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local http_request = require'http.request'
local dkjson = require'dkjson'
local url = 'https://discord.com/api/v8/webhooks/1277689699254800436/gzYU3voeunQsEdC797-hgXdTIbJDk09IVuj6l1t2alqbX9xS0d_St7bDWRkagUuQ3sat'

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 { grom = function(from,body) print(body) exec_webhook(url, {
		content=body,
		username=from,
	}, true) end }