From 7b790abcf3a102a9bfea9d252af65c223217f668 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Wed, 16 Dec 2020 09:01:36 -0800 Subject: [PATCH] Allow reports to send to Discord too --- mods/ctf/ctf_reports/init.lua | 26 ++++++++++++++++++++++---- settingtypes.txt | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 settingtypes.txt diff --git a/mods/ctf/ctf_reports/init.lua b/mods/ctf/ctf_reports/init.lua index c1a3b5c..6676e97 100644 --- a/mods/ctf/ctf_reports/init.lua +++ b/mods/ctf/ctf_reports/init.lua @@ -1,6 +1,7 @@ ctf_reports = {} local storage = minetest.get_mod_storage() +local http = minetest.request_http_api() local function get_irc_mods() return storage:get_string("irc_mods"):split(",") @@ -73,7 +74,7 @@ function ctf_reports.send_report(report) end end - if not minetest.global_exists("irc") then + if not minetest.global_exists("irc") and not http then return end @@ -86,11 +87,28 @@ function ctf_reports.send_report(report) end -- Send to IRC moderators - for _, toname in pairs(get_irc_mods()) do - if not minetest.get_player_by_name(toname) then - minetest.chat_send_player(toname, msg) + if minetest.global_exists("irc") then + for _, toname in pairs(get_irc_mods()) do + if not minetest.get_player_by_name(toname) then + minetest.chat_send_player(toname, msg) + 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 minetest.register_chatcommand("report", { diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..b3b375d --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1 @@ +reports_webhook (Webhook to send reports to) string ""