Fix before_check_muted, before_mute, before_whisper events, add better error messages
This commit is contained in:
parent
de6d783857
commit
ec39f9ed44
2
hash.lua
2
hash.lua
@ -12,7 +12,7 @@ minetest.register_on_chat_message(function(name, message)
|
||||
channel_name = hashchat_lastrecv[name]
|
||||
end
|
||||
|
||||
if not beerchat.execute_callbacks('before_send', name, channel_name, message) then
|
||||
if not beerchat.execute_callbacks('before_send', name, msg, channel_name) then
|
||||
return false
|
||||
end
|
||||
|
||||
|
26
hooks.lua
26
hooks.lua
@ -8,31 +8,31 @@ beerchat.cb.before_whisper = {} -- executed before whisper message is sent
|
||||
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_mute = {} -- executed before player is muted
|
||||
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
|
||||
print('Error: Invalid fn argument for beerchat.register_callback, must be function')
|
||||
print('Error: Invalid fn argument for beerchat.register_callback, must be function. Got ' .. type(fn))
|
||||
return
|
||||
end
|
||||
if type(trigger) ~= 'string' then
|
||||
print('Error: Invalid trigger argument for beerchat.register_callback, must be string')
|
||||
print('Error: Invalid trigger argument for beerchat.register_callback, must be string. Got ' .. type(trigger))
|
||||
return
|
||||
end
|
||||
|
||||
local cb = beerchat.cb
|
||||
local callback_key = trigger
|
||||
|
||||
if not cb[callback_key] then
|
||||
print('Error: Invalid callback trigger event, possible triggers:')
|
||||
if not cb[trigger] then
|
||||
print(string.format('Error: Invalid callback trigger event %s, possible triggers:', trigger))
|
||||
for k,_ in pairs(cb) do
|
||||
print(' -> ' .. k)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
table.insert(cb[callback_key], fn)
|
||||
table.insert(cb[trigger], fn)
|
||||
end
|
||||
|
||||
beerchat.execute_callbacks = function(trigger, ...)
|
||||
@ -42,12 +42,22 @@ beerchat.execute_callbacks = function(trigger, ...)
|
||||
-- This is internal error / dev error, stop processing current event
|
||||
return false
|
||||
end
|
||||
local arg = {...}
|
||||
if arg == nil then
|
||||
print('Error: Missing arguments for beerchat.execute_callbacks')
|
||||
-- This is internal error / dev error, stop processing current event
|
||||
return false
|
||||
end
|
||||
for _,fn in ipairs(cb_list) do
|
||||
local result = fn(unpack(arg))
|
||||
local result, msg = fn(unpack(arg))
|
||||
if result ~= nil then
|
||||
return result
|
||||
return result, msg
|
||||
end
|
||||
end
|
||||
if trigger == 'before_check_muted' then
|
||||
-- requires special handling, might need to create another callback registration for special methods
|
||||
return nil
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
2
jail.lua
2
jail.lua
@ -79,7 +79,7 @@ beerchat.register_callback('before_send_me', function(name, message, channel)
|
||||
end
|
||||
end)
|
||||
|
||||
beerchat.register_callback('before_send_whisper', function(name, message, channel, range)
|
||||
beerchat.register_callback('before_whisper', function(name, message, channel, range)
|
||||
if beerchat.is_player_jailed(name) then
|
||||
return false
|
||||
end
|
||||
|
@ -22,7 +22,7 @@ beerchat.whisper = function(name, message)
|
||||
elseif msg == "" then
|
||||
minetest.chat_send_player(name, "Please enter the message you would like to whisper to nearby players")
|
||||
else
|
||||
local cb_result, cb_message = beerchat.execute_callbacks('before_send_whisper', name, msg, beerchat.main_channel_name, radius)
|
||||
local cb_result, cb_message = beerchat.execute_callbacks('before_whisper', name, msg, beerchat.main_channel_name, radius)
|
||||
if not cb_result then
|
||||
if cb_message then return false, cb_message else return false end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user