From 1af799f9051c13f864d17e8ff6c1f006a4b1da8a Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 2 Feb 2018 18:23:04 +0000 Subject: [PATCH] Add filter.mute --- init.lua | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index 1d02a24..ae9933a 100644 --- a/init.lua +++ b/init.lua @@ -66,6 +66,26 @@ function filter.check_message(name, message) return true end +function filter.mute(name, duration) + do + local privs = minetest.get_player_privs(name) + privs.shout = nil + minetest.set_player_privs(name, privs) + end + minetest.chat_send_player(name, "Watch your language! You have been temporarily muted") + + muted[name] = true + + minetest.after(duration * 60, function() + muted[name] = nil + minetest.chat_send_player(name, "Chat privilege reinstated. Please do not abuse chat.") + + local privs = minetest.get_player_privs(name) + privs.shout = true + minetest.set_player_privs(name, privs) + end) +end + function filter.on_violation(name, message) violations[name] = (violations[name] or 0) + 1 @@ -76,19 +96,7 @@ function filter.on_violation(name, message) minetest.kick_player(name, "Please mind your language!") else resolution = "muted" - local privs = minetest.get_player_privs(name) - privs.shout = nil - minetest.set_player_privs(name, privs) - minetest.chat_send_player(name, "Watch your language! You have been temporarily muted") - - muted[name] = true - - minetest.after(60, function() - muted[name] = nil - minetest.chat_send_player(name, "Chat privilege reinstated. Please do not abuse chat.") - privs.shout = true - minetest.set_player_privs(name, privs) - end) + filter.mute(name, 1) end minetest.log("action", "VIOLATION (" .. resolution .. "): <" .. name .. "> ".. message)