From 629e87797072c9216d83d133cee1adc80e043f9e Mon Sep 17 00:00:00 2001 From: crabman77 Date: Wed, 23 Dec 2015 22:53:59 +0100 Subject: [PATCH] add action_timers for report mod and rewrite code --- mods/report/depends.txt | 1 + mods/report/init.lua | 69 +++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/mods/report/depends.txt b/mods/report/depends.txt index 16a29746..7381e1c2 100644 --- a/mods/report/depends.txt +++ b/mods/report/depends.txt @@ -1,2 +1,3 @@ email +action_timers unified_inventory? diff --git a/mods/report/init.lua b/mods/report/init.lua index 1dacc232..60197c06 100644 --- a/mods/report/init.lua +++ b/mods/report/init.lua @@ -1,3 +1,30 @@ +report = {} + +function report.send(sender, message) + -- Send to online moderators / admins + -- Get comma separated list of online moderators and admins + local mods = {} + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + if minetest.check_player_privs(name, {kick = true, ban = true}) then + table.insert(mods, name) + minetest.chat_send_player(name, "-!- " .. sender .. " reported: " .. message) + end + end + + if #mods > 0 then + local mod_list = table.concat(mods, ", ") + email.send_mail(sender, minetest.setting_get("name"), + "Report: " .. message .. " (mods online: " .. mod_list .. ")") + return true, "Reported. Moderators currently online: " .. mod_list + else + email.send_mail(sender, minetest.setting_get("name"), + "Report: " .. message .. " (no mods online)") + return true, "Reported. We'll get back to you." + end +end + + minetest.register_chatcommand("report", { func = function(name, param) param = param:trim() @@ -10,28 +37,7 @@ minetest.register_chatcommand("report", { 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 - -- Get comma separated list of online moderators and admins - local mods = {} - for _, player in pairs(minetest.get_connected_players()) do - local name = player:get_player_name() - if minetest.check_player_privs(name, {kick = true, ban = true}) then - table.insert(mods, name) - minetest.chat_send_player(name, "-!- " .. name .. " reported: " .. param) - end - end - - if #mods > 0 then - local mod_list = table.concat(mods, ", ") - email.send_mail(name, minetest.setting_get("name"), - "Report: " .. param .. " (mods online: " .. mod_list .. ")") - return true, "Reported. Moderators currently online: " .. mod_list - else - email.send_mail(name, minetest.setting_get("name"), - "Report: " .. param .. " (no mods online)") - return true, "Reported. We'll get back to you." - end + return action_timers.wrapper(name, "report", "report_" .. name, 600, report.send, {name, param}) end }) @@ -61,21 +67,10 @@ if minetest.get_modpath("unified_inventory") then return end local name = player:get_player_name() - local cmd_def = core.chatcommands["report"] - if not cmd_def then - return - end - local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs) - if has_privs then - core.set_last_run_mod(cmd_def.mod_origin) - local success, message = cmd_def.func(name, fields.text) - if message then - core.chat_send_player(name, message) - end - else - core.chat_send_player(name, "You don't have permission" - .. " to run this command (missing privileges: " - .. table.concat(missing_privs, ", ") .. ")") + + local success, message = action_timers.wrapper(name, "report", "report_" .. name, 600, report.send, {name, fields.text}) + if message then + core.chat_send_player(name, message) end return true -- Handled fields reception end)