Changed callback abort condition, add mute check and before_send for jail
parent
2b5bb853df
commit
f84efad091
19
common.lua
19
common.lua
|
@ -1,9 +1,10 @@
|
|||
|
||||
beerchat.has_player_muted_player = function(name, other_name)
|
||||
-- ignore muting for jailed users
|
||||
if beerchat.is_player_jailed(name) then
|
||||
return false
|
||||
local cb_result = beerchat.execute_callbacks('before_check_muted', name, other_name)
|
||||
if cb_result ~= nil then
|
||||
return cb_result
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(name)
|
||||
-- check jic method is used incorrectly
|
||||
if not player then
|
||||
|
@ -21,16 +22,14 @@ beerchat.is_player_subscribed_to_channel = function(name, channel)
|
|||
end -- is_player_subscribed_to_channel
|
||||
|
||||
beerchat.send_message = function(name, message, channel)
|
||||
local jailed = beerchat.is_player_jailed(name)
|
||||
local is_jail_channel = channel == beerchat.jail_channel_name
|
||||
if jailed and not is_jail_channel then
|
||||
|
||||
if not beerchat.execute_callbacks('before_send', name, message, channel) then
|
||||
return
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name, message)
|
||||
if is_jail_channel then
|
||||
return
|
||||
end
|
||||
-- TODO: read player settings for channel sounds
|
||||
|
||||
-- TODO: read player settings for channel sounds
|
||||
if beerchat.enable_sounds and channel ~= beerchat.main_channel_name then
|
||||
minetest.sound_play(beerchat.channel_message_sound, { to_player = name, gain = beerchat.sounds_default_gain } )
|
||||
end
|
||||
|
|
20
hooks.lua
20
hooks.lua
|
@ -1,12 +1,13 @@
|
|||
|
||||
beerchat.cb = {} -- all custom callbacks
|
||||
|
||||
beerchat.cb.before_send = {} -- executed before sending message
|
||||
beerchat.cb.before_receive = {} -- executed before receiving message
|
||||
beerchat.cb.before_join = {} -- executed before channel is joined
|
||||
beerchat.cb.before_leave = {} -- executed before channel is leaved
|
||||
beerchat.cb.before_invite = {} -- excuted before channel invitation takes place
|
||||
beerchat.cb.on_forced_join = {} -- executed right after player is forced to channel
|
||||
beerchat.cb.before_send = {} -- executed before sending message
|
||||
beerchat.cb.before_receive = {} -- executed before receiving message
|
||||
beerchat.cb.before_join = {} -- executed before channel is joined
|
||||
beerchat.cb.before_leave = {} -- executed before channel is leaved
|
||||
beerchat.cb.before_invite = {} -- excuted before channel invitation takes place
|
||||
beerchat.cb.before_check_muted = {} -- executed before has_player_muted_player checks
|
||||
beerchat.cb.on_forced_join = {} -- executed right after player is forced to channel
|
||||
|
||||
beerchat.register_callback = function(trigger, fn)
|
||||
if type(fn) ~= 'function' then
|
||||
|
@ -32,7 +33,7 @@ beerchat.register_callback = function(trigger, fn)
|
|||
table.insert(cb[callback_key], fn)
|
||||
end
|
||||
|
||||
beerchat.execute_callbacks = function(trigger)
|
||||
beerchat.execute_callbacks = function(trigger, ...)
|
||||
local cb_list = beerchat.cb[trigger]
|
||||
if not cb_list then
|
||||
print('Error: Invalid trigger argument for beerchat.execute_callbacks')
|
||||
|
@ -40,8 +41,9 @@ beerchat.execute_callbacks = function(trigger)
|
|||
return false
|
||||
end
|
||||
for _,fn in ipairs(cb_list) do
|
||||
if not fn(unpack(arg) then
|
||||
return false
|
||||
local result = fn(unpack(arg)
|
||||
if result ~= nil then
|
||||
return result
|
||||
end
|
||||
end
|
||||
return true
|
||||
|
|
21
jail.lua
21
jail.lua
|
@ -16,28 +16,40 @@ beerchat.register_callback('before_invite', function(sender, recipient, channel)
|
|||
if beerchat.is_player_jailed(player_name) then
|
||||
return false, player_name .. " is in chat-jail, no inviting."
|
||||
end
|
||||
return true
|
||||
end)
|
||||
|
||||
beerchat.register_callback('before_mute', function(name, target)
|
||||
if beerchat.is_player_jailed(name) then
|
||||
return false, "You are in chat-jail, no muting for you."
|
||||
end
|
||||
return true
|
||||
end)
|
||||
|
||||
beerchat.register_callback('before_join', function(name, channel)
|
||||
if beerchat.is_player_jailed(name) then
|
||||
return false, "You are in chat-jail, no joining channels for you."
|
||||
end
|
||||
return true
|
||||
end)
|
||||
|
||||
beerchat.register_callback('before_leave', function(name, channel)
|
||||
if beerchat.is_player_jailed(name) then
|
||||
return false, "You are in chat-jail, no leaving for you."
|
||||
end
|
||||
return true
|
||||
end)
|
||||
|
||||
beerchat.register_callback('before_send', function(name, message, channel)
|
||||
local jailed = beerchat.is_player_jailed(name)
|
||||
local is_jail_channel = channel == beerchat.jail_channel_name
|
||||
if jailed and not is_jail_channel then
|
||||
-- override default send method to mute pings for jailed users
|
||||
minetest.chat_send_player(name, message)
|
||||
return false
|
||||
end
|
||||
end)
|
||||
|
||||
beerchat.register_callback('before_check_muted', function(name, muted)
|
||||
if beerchat.is_player_jailed(name) then
|
||||
return false
|
||||
end
|
||||
end)
|
||||
|
||||
beerchat.register_callback('on_forced_join', function(name, target, channel, target_meta)
|
||||
|
@ -49,5 +61,4 @@ beerchat.register_callback('on_forced_join', function(name, target, channel, tar
|
|||
target_meta:set_int("beerchat:jailed", 0)
|
||||
beerchat.jail_list[target] = nil
|
||||
end
|
||||
return true
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue