properly implement at replies and deaf import
This commit is contained in:
parent
76532e3771
commit
4ea2f7a667
15
api.lua
15
api.lua
@ -7,6 +7,8 @@ chat_modes = {}
|
|||||||
|
|
||||||
minetest.register_privilege("cmodeswitch", "Player can switch their chat mode.")
|
minetest.register_privilege("cmodeswitch", "Player can switch their chat mode.")
|
||||||
|
|
||||||
|
-- ========================================================
|
||||||
|
-- Don't litter
|
||||||
local debug_on = false
|
local debug_on = false
|
||||||
function chat_modes.dodebug(message, artefact)
|
function chat_modes.dodebug(message, artefact)
|
||||||
if not debug_on then return end
|
if not debug_on then return end
|
||||||
@ -54,6 +56,7 @@ function chat_modes.register_interceptor(name, handler)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Send a player chat
|
-- Send a player chat
|
||||||
|
-- Residual function, should be removed
|
||||||
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()
|
||||||
@ -233,7 +236,7 @@ end)
|
|||||||
|
|
||||||
-- ================================
|
-- ================================
|
||||||
-- Load defaults
|
-- Load defaults
|
||||||
dodebug("Checking for default functions")
|
dodebug("Loading default modes")
|
||||||
|
|
||||||
if loadmodes then
|
if loadmodes then
|
||||||
dodebug("Default modes found:",loadmodes:split(","))
|
dodebug("Default modes found:",loadmodes:split(","))
|
||||||
@ -246,8 +249,18 @@ else
|
|||||||
dofile(minetest.get_modpath("chat_modes").."/shout_mode.lua" )
|
dofile(minetest.get_modpath("chat_modes").."/shout_mode.lua" )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ================================
|
||||||
-- Load standard interceptors
|
-- Load standard interceptors
|
||||||
|
|
||||||
|
dodebug("Loading default interceptors")
|
||||||
|
|
||||||
-- Allow direct pinging
|
-- Allow direct pinging
|
||||||
dofile(minetest.get_modpath("chat_modes").."/atreply_interceptor.lua")
|
dofile(minetest.get_modpath("chat_modes").."/atreply_interceptor.lua")
|
||||||
|
|
||||||
|
-- Deafness
|
||||||
|
-- Deaf filter is processed after any other interceptors may have
|
||||||
|
-- modified the target list
|
||||||
|
-- FIXME if other interceptors discard the original list, this effect is nulled....
|
||||||
|
dofile(minetest.get_modpath("chat_modes").."/deaf_interceptor.lua")
|
||||||
|
|
||||||
dodebug("Loaded chat modes")
|
dodebug("Loaded chat modes")
|
||||||
|
@ -21,16 +21,14 @@ local function playping(playername)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local function removefrom(players, playername)
|
-- Returns the target if it does not exist in the set
|
||||||
local i = 1
|
-- else returns nil
|
||||||
while players[i] do
|
local function needstarget(targetset, target)
|
||||||
if players[i]:get_player_name() == playername then
|
for _,testtarget in pairs(targetset) do
|
||||||
table.remove(players, i)
|
if testtarget == target then
|
||||||
break
|
return target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return players
|
|
||||||
end
|
end
|
||||||
|
|
||||||
chat_modes.register_interceptor("atreply", function(sender, message, targets)
|
chat_modes.register_interceptor("atreply", function(sender, message, targets)
|
||||||
@ -42,21 +40,23 @@ chat_modes.register_interceptor("atreply", function(sender, message, targets)
|
|||||||
|
|
||||||
local includes = {"triggerone"}
|
local includes = {"triggerone"}
|
||||||
local private = false
|
local private = false
|
||||||
|
local newtargets = {}
|
||||||
|
|
||||||
-- Players mentioned at start of message
|
-- Players mentioned at start of message
|
||||||
-- Only send to them
|
-- Only send to them
|
||||||
while messageparts[1] and messageparts[1]:sub(1,1) == '@' do
|
while messageparts[1] and messageparts[1]:sub(1,1) == '@' do
|
||||||
local token = table.remove(messageparts, 1)
|
local token = table.remove(messageparts, 1)
|
||||||
local dmstring = "DM from "..sender..": "
|
|
||||||
|
|
||||||
local tname = token:sub(2, #token)
|
local tname = token:sub(2, #token)
|
||||||
chat_modes.chatsend(tname, dmstring..message)
|
|
||||||
playping(tname)
|
local targetplayer = needstarget(targets, minetest.get_player_by_name(tname) )
|
||||||
|
if targetplayer then
|
||||||
|
newtargets[#newtargets+1] = targetplayer
|
||||||
|
playping(tname)
|
||||||
|
end
|
||||||
private = true
|
private = true
|
||||||
end
|
end
|
||||||
if private then
|
if private then
|
||||||
chat_modes.dodebug("DECLINE")
|
return newtargets
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
while includes[1] do -- hence "triggerone" to do it at least once
|
while includes[1] do -- hence "triggerone" to do it at least once
|
||||||
@ -64,16 +64,22 @@ chat_modes.register_interceptor("atreply", function(sender, message, targets)
|
|||||||
includes = nextin.includes
|
includes = nextin.includes
|
||||||
messageparts = nextin.mparts
|
messageparts = nextin.mparts
|
||||||
|
|
||||||
local dmstring = "DM from "..sender..": "
|
|
||||||
|
|
||||||
for _,pname in pairs(includes) do
|
for _,pname in pairs(includes) do
|
||||||
chat_modes.chatsend(pname, dmstring..message)
|
local targetplayer = needstarget(targets, minetest.get_player_by_name(tname) )
|
||||||
playping(pname)
|
if targetplayer then
|
||||||
targets = removefrom(table.copy(targets), playername)
|
newtargets[#newtargets+1] = targetplayer
|
||||||
|
playping(tname)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
chat_modes.dodebug("ALLOW")
|
for _,residualplayer in pairs(targets) do
|
||||||
return targets -- Allow processing the rest
|
local targetplayer = needstarget(newtargets, residualplayer )
|
||||||
|
if targetplayer then
|
||||||
|
newtargets[#newtargets+1] = targetplayer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return newtargets
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user