mirror of
https://github.com/rubenwardy/report.git
synced 2025-01-09 01:10:25 +01:00
Validate input
This commit is contained in:
parent
474ea755f3
commit
03441a5fee
36
init.lua
36
init.lua
@ -4,25 +4,37 @@ end
|
|||||||
|
|
||||||
minetest.register_chatcommand("report", {
|
minetest.register_chatcommand("report", {
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
|
param = param:trim()
|
||||||
|
if param == "" then
|
||||||
|
return false, "Please add a message to your report. " ..
|
||||||
|
"If it's about (a) particular player(s), please also include their name(s)."
|
||||||
|
end
|
||||||
|
local _, count = string.gsub(param, " ", "")
|
||||||
|
if count == 0 then
|
||||||
|
minetest.chat_send_player(name, "If you're reporting a player, " ..
|
||||||
|
"you should also include a reason why. (Eg: swearing, sabotage)")
|
||||||
|
end
|
||||||
|
|
||||||
-- Send to online moderators / admins
|
-- Send to online moderators / admins
|
||||||
-- Get comma separated list of online moderators and admins
|
-- Get comma separated list of online moderators and admins
|
||||||
local mods = ""
|
local mods = {}
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if minetest.check_player_privs(name, {kick=true,ban=true}) then
|
if minetest.check_player_privs(name, {kick = true, ban = true}) then
|
||||||
if mods ~= "" then
|
table.insert(mods, name)
|
||||||
mods = mods .. ", "
|
|
||||||
end
|
|
||||||
mods = mods .. name
|
|
||||||
minetest.chat_send_player(name, "-!- " .. name .. " reported: " .. param)
|
minetest.chat_send_player(name, "-!- " .. name .. " reported: " .. param)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- I hope that none of the moderators are called "none"!
|
if #mods > 0 then
|
||||||
if mods == "" then
|
mod_list = table.concat(mods, ", ")
|
||||||
mods = "none"
|
chatplus.send_mail(name, minetest.setting_get("name"),
|
||||||
|
"Report: " .. param .. " (mods online: " .. mod_list .. ")")
|
||||||
|
return true, "Reported. Moderators currently online: " .. mod_list
|
||||||
|
else
|
||||||
|
chatplus.send_mail(name, minetest.setting_get("name"),
|
||||||
|
"Report: " .. param .. " (no mods online)")
|
||||||
|
return true, "Reported. We'll get back to you."
|
||||||
end
|
end
|
||||||
chatplus.send_mail(name, minetest.setting_get("name"),
|
|
||||||
"Report: " .. param .. " (mods online: " .. mods .. ")")
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user