2021-07-25 00:01:37 +02:00
|
|
|
local S = minetest.get_translator("report")
|
2021-07-24 12:48:31 +02:00
|
|
|
|
2021-07-25 00:01:37 +02:00
|
|
|
local storage = minetest.get_mod_storage()
|
|
|
|
assert(storage, "mod_storage is required")
|
2021-07-24 12:48:31 +02:00
|
|
|
|
|
|
|
local function get_modo_list()
|
2021-07-25 00:01:37 +02:00
|
|
|
local store = storage:get_string("report")
|
|
|
|
if store then
|
|
|
|
return minetest.deserialize(store) or {}
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil
|
|
|
|
end
|
2021-07-24 12:48:31 +02:00
|
|
|
|
2021-07-25 00:01:37 +02:00
|
|
|
local function is_known_modo(name)
|
|
|
|
for _, modo in ipairs(get_modo_list()) do
|
|
|
|
if modo == name then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
2021-07-24 12:48:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2021-07-25 00:01:37 +02:00
|
|
|
-- Obtenir les privs du player
|
|
|
|
local player_name = player:get_player_name()
|
|
|
|
local is_modo = minetest.check_player_privs(player_name, {kick = true, ban = true})
|
|
|
|
|
|
|
|
-- Le joueur est-il un modérateur connu ?
|
|
|
|
local known = is_known_modo(player_name)
|
|
|
|
|
|
|
|
-- Ajouter ou supprimer le joueur de la liste des modérateurs
|
|
|
|
if not known and is_modo then
|
|
|
|
-- Ajouter nom du player dans liste modos
|
|
|
|
local modos = get_modo_list()
|
|
|
|
table.insert(modos, player_name)
|
|
|
|
storage:set_string("report", minetest.serialize(modos))
|
|
|
|
elseif known and not is_modo then
|
|
|
|
-- Supprimer nom du player de la liste modos
|
|
|
|
local modos = get_modo_list()
|
|
|
|
for i, modo in ipairs(modos) do
|
|
|
|
if modo == player_name then
|
|
|
|
table.remove(modos, i)
|
|
|
|
storage:set_string("report", minetest.serialize(modos))
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-07-24 12:48:31 +02:00
|
|
|
end)
|
|
|
|
|
2015-12-11 18:45:32 +01:00
|
|
|
minetest.register_chatcommand("report", {
|
2021-07-25 00:01:37 +02:00
|
|
|
description = S("Report: @1 to see moderators list. @2 is the message to report to moderators.", "'modos'", "'msg'"),
|
|
|
|
params = "modos|msg",
|
2015-12-11 18:45:32 +01:00
|
|
|
func = function(name, param)
|
2015-12-18 05:11:11 +01:00
|
|
|
param = param:trim()
|
|
|
|
if param == "" then
|
2021-07-25 00:01:37 +02:00
|
|
|
return false, S("Please write a message for the report. If it's about one or several players in particular, please give their name.")
|
|
|
|
end
|
|
|
|
if param == "modos" then
|
|
|
|
return true, S("Moderators list: @1", table.concat(get_modo_list(), ", "))
|
2015-12-18 05:11:11 +01:00
|
|
|
end
|
|
|
|
local _, count = string.gsub(param, " ", "")
|
|
|
|
if count == 0 then
|
2021-07-25 00:01:37 +02:00
|
|
|
minetest.chat_send_player(name, S("If you are reporting a player's attitude, you should also say why. (Ex: insult, sabotage)"))
|
2015-12-18 05:11:11 +01:00
|
|
|
end
|
|
|
|
|
2015-12-11 18:45:32 +01:00
|
|
|
-- Send to online moderators / admins
|
|
|
|
-- Get comma separated list of online moderators and admins
|
2021-07-25 00:01:37 +02:00
|
|
|
local modos_online = {}
|
2015-12-11 18:45:32 +01:00
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
2015-12-24 20:20:10 +01:00
|
|
|
local toname = player:get_player_name()
|
2021-07-25 00:01:37 +02:00
|
|
|
if is_known_modo(toname) then
|
|
|
|
table.insert(modos_online, toname)
|
|
|
|
minetest.chat_send_player(toname, S("-!- @1 has reported: @2", name, param))
|
2015-12-11 18:45:32 +01:00
|
|
|
end
|
|
|
|
end
|
2015-12-18 05:11:11 +01:00
|
|
|
|
2021-07-25 00:01:37 +02:00
|
|
|
local admin = minetest.setting_get("name")
|
|
|
|
|
|
|
|
if #modos_online > 0 then
|
|
|
|
local mod_list = table.concat(modos_online, ", ")
|
|
|
|
email.send_mail(name, admin, S("Report: @1 (online moderator(s): @2)", param, mod_list))
|
|
|
|
for _, modo in ipairs(get_modo_list()) do
|
|
|
|
if modo ~= admin then
|
|
|
|
email.send_mail(name, modo, S("Report: @1 (online moderator(s): @2)", param, mod_list))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true, S("Reported. Online moderator(s): @1", mod_list)
|
2015-12-18 05:11:11 +01:00
|
|
|
else
|
2021-08-11 21:54:30 +02:00
|
|
|
email.send_mail(name, admin, S("Report: @1 (no online moderator)", param))
|
2021-07-25 00:01:37 +02:00
|
|
|
for _, modo in ipairs(get_modo_list()) do
|
|
|
|
if modo ~= admin then
|
|
|
|
email.send_mail(name, modo, S("Report: @1 (no online moderator)", param))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true, S("Reported. We will get back to you.")
|
2015-12-11 18:45:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
2022-07-02 15:58:06 +02:00
|
|
|
|
|
|
|
minetest.log("action", "[report] mod loaded.")
|