move deaf mode to an interceptor
This commit is contained in:
parent
c026ee0e9d
commit
8e9b9f5a7e
24
api.lua
24
api.lua
@ -33,9 +33,6 @@ local interceptors = {} -- name --> function(playername, message, playerlist)
|
|||||||
-- Keep track of what mode players are in
|
-- Keep track of what mode players are in
|
||||||
local playermodes = {} -- playername => modestring
|
local playermodes = {} -- playername => modestring
|
||||||
|
|
||||||
-- Keep track of players who have deafened themselves
|
|
||||||
local deafplayers = {}
|
|
||||||
|
|
||||||
-- If the user activates chat_modes but does not properly configure it, just activate "shout"
|
-- If the user activates chat_modes but does not properly configure it, just activate "shout"
|
||||||
local defaultmode = minetest.setting_get("chat_modes.mode") or "shout"
|
local defaultmode = minetest.setting_get("chat_modes.mode") or "shout"
|
||||||
|
|
||||||
@ -56,15 +53,13 @@ function chat_modes.register_interceptor(name, handler)
|
|||||||
interceptors[name] = handler
|
interceptors[name] = handler
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Send a player chat, unless the player has set themselves ass deaf
|
-- Send a player chat
|
||||||
function chat_modes.chatsend(player, message)
|
function chat_modes.chatsend(player, message)
|
||||||
if type(player) ~= "string" then
|
if type(player) ~= "string" then
|
||||||
player = player:get_player_name()
|
player = player:get_player_name()
|
||||||
end
|
end
|
||||||
|
|
||||||
if not deafplayers[player] then
|
|
||||||
minetest.chat_send_player(player, message)
|
minetest.chat_send_player(player, message)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ================================
|
-- ================================
|
||||||
@ -109,24 +104,10 @@ end
|
|||||||
-- General chat utilities
|
-- General chat utilities
|
||||||
dodebug("Define extra commands")
|
dodebug("Define extra commands")
|
||||||
|
|
||||||
minetest.register_chatcommand("deaf", {
|
|
||||||
description = "Toggle deaf status. If you are deaf (Deaf mode 'on'), you do not receive any chat messages.",
|
|
||||||
privs = {shout = true},
|
|
||||||
func = function(playername, args)
|
|
||||||
if deafplayers[playername] then
|
|
||||||
deafplayers[playername] = nil
|
|
||||||
minetest.chat_send_player(playername, "Deaf mode OFF")
|
|
||||||
else
|
|
||||||
deafplayers[playername] = true
|
|
||||||
minetest.chat_send_player(playername, "Deaf mode ON")
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Send message to all, named after the UNIX command of the same name
|
-- Send message to all, named after the UNIX command of the same name
|
||||||
minetest.register_chatcommand("wall", {
|
minetest.register_chatcommand("wall", {
|
||||||
params = "<compulsory message>",
|
params = "<compulsory message>",
|
||||||
description = "Send a message to all players, regardless of chat mode or deaf status - for moderators.",
|
description = "Send a message to all players, regardless of chat mode or interceptors - for moderators.",
|
||||||
privs = {shout = true, basic_privs = true},
|
privs = {shout = true, basic_privs = true},
|
||||||
func = function(playername, message)
|
func = function(playername, message)
|
||||||
minetest.chat_send_all("MODERATOR "..playername..": "..message)
|
minetest.chat_send_all("MODERATOR "..playername..": "..message)
|
||||||
@ -177,7 +158,6 @@ minetest.register_chatcommand("chatmodes", {
|
|||||||
|
|
||||||
minetest.chat_send_player(playername, modename.." : "..helptext )
|
minetest.chat_send_player(playername, modename.." : "..helptext )
|
||||||
end
|
end
|
||||||
minetest.chat_send_player(playername, "deaf : stop receiving any chats from players")
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
28
deaf_interceptor.lua
Normal file
28
deaf_interceptor.lua
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
-- Keep track of players who have deafened themselves
|
||||||
|
local deafplayers = {}
|
||||||
|
|
||||||
|
minetest.register_chatcommand("deaf", {
|
||||||
|
description = "Toggle deaf status. If you are deaf (Deaf mode 'on'), you do not receive any chat messages.",
|
||||||
|
privs = {shout = true},
|
||||||
|
func = function(playername, args)
|
||||||
|
if deafplayers[playername] then
|
||||||
|
deafplayers[playername] = nil
|
||||||
|
minetest.chat_send_player(playername, "Deaf mode OFF")
|
||||||
|
else
|
||||||
|
deafplayers[playername] = true
|
||||||
|
minetest.chat_send_player(playername, "Deaf mode ON")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
chat_modes.register_interceptor("deaf mode", function(sender, message, targets)
|
||||||
|
local newtargets = {}
|
||||||
|
|
||||||
|
for _,player in pairs(targets) do
|
||||||
|
if not deafplayers[player:get_player_name()] then
|
||||||
|
newtargets[#newtargets+1] = player
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return newtargets
|
||||||
|
end)
|
Loading…
x
Reference in New Issue
Block a user