Allow reports to send to Discord too

This commit is contained in:
LoneWolfHT 2020-12-16 09:01:36 -08:00
parent 3afcdf4ed0
commit 7b790abcf3
2 changed files with 23 additions and 4 deletions

View file

@ -1,6 +1,7 @@
ctf_reports = {} ctf_reports = {}
local storage = minetest.get_mod_storage() local storage = minetest.get_mod_storage()
local http = minetest.request_http_api()
local function get_irc_mods() local function get_irc_mods()
return storage:get_string("irc_mods"):split(",") return storage:get_string("irc_mods"):split(",")
@ -73,7 +74,7 @@ function ctf_reports.send_report(report)
end end
end end
if not minetest.global_exists("irc") then if not minetest.global_exists("irc") and not http then
return return
end end
@ -86,11 +87,28 @@ function ctf_reports.send_report(report)
end end
-- Send to IRC moderators -- Send to IRC moderators
if minetest.global_exists("irc") then
for _, toname in pairs(get_irc_mods()) do for _, toname in pairs(get_irc_mods()) do
if not minetest.get_player_by_name(toname) then if not minetest.get_player_by_name(toname) then
minetest.chat_send_player(toname, msg) minetest.chat_send_player(toname, msg)
end end
end end
end
-- Send to discord
if http and minetest.settings:get("reports_webhook") then
http.fetch({
method = "POST",
url = minetest.settings:get("reports_webhook"),
extra_headers = {"Content-Type: application/json"},
timeout = 5,
data = minetest.write_json({
username = "Ingame Report",
avatar_url = "https://cdn.discordapp.com/avatars/447857790589992966/7ab615bae6196346bac795e66ba873dd.png",
content = msg,
}),
}, function() end)
end
end end
minetest.register_chatcommand("report", { minetest.register_chatcommand("report", {

1
settingtypes.txt Normal file
View file

@ -0,0 +1 @@
reports_webhook (Webhook to send reports to) string ""