diff --git a/plugin/init.lua b/plugin/init.lua index 6b45815..ecc2042 100644 --- a/plugin/init.lua +++ b/plugin/init.lua @@ -26,6 +26,9 @@ load_plugin("whisper", true) -- Adds "/chat_jail playername" and "/chat_unjail playername" commands load_plugin("jail", false) +-- Allow muting remote users +load_plugin("remote_mute", false) + -- Removes control characters from incoming messages load_plugin("cleaner", false) diff --git a/plugin/remote_mute.lua b/plugin/remote_mute.lua new file mode 100644 index 0000000..07444e9 --- /dev/null +++ b/plugin/remote_mute.lua @@ -0,0 +1,48 @@ +local remote_muted = {} + +minetest.register_chatcommand("remote_mute", { + params = " [ ...]", + description = ("Mute remote users. Requires %s privilege."):format(beerchat.jail.priv), + privs = { [beerchat.jail.priv] = true }, + func = function(_, param) + if not param or param == "" then + return false, "ERROR: Invalid number of arguments. Please supply the player name(s)." + end + local names = string.gmatch(param, "[^%s,]+") + for remote_name in names do + remote_muted[remote_name] = true + end + return true + end +}) + +minetest.register_chatcommand("remote_unmute", { + params = "[ ...]", + description = ("Unmute remote users or list muted remote users. Requires %s privilege."):format(beerchat.jail.priv), + privs = { [beerchat.jail.priv] = true }, + func = function(name, param) + if not param or param == "" then + local names = {} + for remote_name,_ in pairs(remote_muted) do + table.insert(names, remote_name) + end + if #names > 0 then + minetest.chat_send_player(name, "Muted remote users: " .. table.concat(names, ", ")) + else + minetest.chat_send_player(name, "No muted remote users.") + end + else + local names = string.gmatch(param, "[^%s,]+") + for remote_name in names do + remote_muted[remote_name] = nil + end + end + return true + end +}) + +beerchat.register_callback('on_http_receive', function(msg_data) + if remote_muted[msg_data.username .. "@" .. msg_data.name] then + return false + end +end)