-
Notifications
You must be signed in to change notification settings - Fork 7
/
report_webhook.lua
37 lines (34 loc) · 1006 Bytes
/
report_webhook.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local http = assert(...)
local webhook_url = minetest.settings:get("secure.bls.report_webhook_url")
-- Don't do anything if no webhook is configured
if not webhook_url or webhook_url == "" or
not minetest.registered_chatcommands["report"] then
return
end
local function send_webhook(player_name, report)
local data = minetest.write_json({
embeds = {
{
title = "Report from " .. player_name,
description = report
}
}
})
http.fetch({
url = webhook_url,
method = "POST",
extra_headers = {"Content-Type: application/json"},
data = data,
post_data = data
}, function() end)
end
local old_func = minetest.registered_chatcommands["report"].func
minetest.override_chatcommand("report", {
func = function(name, param)
local ok, msg = old_func(name, param)
if ok then
send_webhook(name, param)
end
return ok, msg
end,
})