Simplify callback usage, override /tell, fix/add info messages
This commit is contained in:
parent
998150ac38
commit
1d7e810928
@ -16,5 +16,3 @@ read_globals = {
|
|||||||
-- Deps
|
-- Deps
|
||||||
"xban"
|
"xban"
|
||||||
}
|
}
|
||||||
|
|
||||||
files["jail.lua"] = { unused_args = false }
|
|
||||||
|
@ -191,14 +191,8 @@ local join_channel = {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local cb_result, cb_message = beerchat.execute_callbacks(
|
if not beerchat.execute_callbacks('before_join', name, channel_name) then
|
||||||
'before_join', name, channel_name)
|
return false
|
||||||
if not cb_result then
|
|
||||||
if cb_message then
|
|
||||||
return false, cb_message
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
beerchat.playersChannels[name] = beerchat.playersChannels[name] or {}
|
beerchat.playersChannels[name] = beerchat.playersChannels[name] or {}
|
||||||
@ -236,14 +230,8 @@ local leave_channel = {
|
|||||||
.. ", no need to leave."
|
.. ", no need to leave."
|
||||||
end
|
end
|
||||||
|
|
||||||
local cb_result, cb_message = beerchat.execute_callbacks(
|
if not beerchat.execute_callbacks('before_leave', name, channel_name) then
|
||||||
'before_leave', name, channel_name)
|
return false
|
||||||
if not cb_result then
|
|
||||||
if cb_message then
|
|
||||||
return false, cb_message
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
beerchat.playersChannels[name][channel_name] = nil
|
beerchat.playersChannels[name][channel_name] = nil
|
||||||
@ -304,14 +292,8 @@ local invite_channel = {
|
|||||||
if not minetest.get_player_by_name(player_name) then
|
if not minetest.get_player_by_name(player_name) then
|
||||||
return false, "ERROR: " .. player_name .. " does not exist or is not online."
|
return false, "ERROR: " .. player_name .. " does not exist or is not online."
|
||||||
else
|
else
|
||||||
local cb_result, cb_message = beerchat.execute_callbacks(
|
if not beerchat.execute_callbacks('before_invite', name, player_name, channel_name) then
|
||||||
'before_invite', name, player_name, channel_name)
|
return false
|
||||||
if not cb_result then
|
|
||||||
if cb_message then
|
|
||||||
return false, cb_message
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if not beerchat.has_player_muted_player(player_name, name) then
|
if not beerchat.has_player_muted_player(player_name, name) then
|
||||||
if beerchat.enable_sounds then
|
if beerchat.enable_sounds then
|
||||||
@ -345,13 +327,8 @@ local mute_player = {
|
|||||||
.. "messages of this user, regardless of what channel his user sends messages to.",
|
.. "messages of this user, regardless of what channel his user sends messages to.",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
|
|
||||||
local cb_result, cb_message = beerchat.execute_callbacks('before_mute', name, param)
|
if not beerchat.execute_callbacks('before_mute', name, param) then
|
||||||
if not cb_result then
|
return false
|
||||||
if cb_message then
|
|
||||||
return false, cb_message
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not param or param == "" then
|
if not param or param == "" then
|
||||||
@ -455,14 +432,8 @@ beerchat.force_player_to_channel = function(name, param)
|
|||||||
beerchat.currentPlayerChannel[player_name] = channel_name
|
beerchat.currentPlayerChannel[player_name] = channel_name
|
||||||
meta:set_string("beerchat:current_channel", channel_name)
|
meta:set_string("beerchat:current_channel", channel_name)
|
||||||
|
|
||||||
local cb_result, cb_message = beerchat.execute_callbacks(
|
if not beerchat.execute_callbacks('on_forced_join', name, player_name, channel_name, meta) then
|
||||||
'on_forced_join', name, player_name, channel_name, meta)
|
return false
|
||||||
if not cb_result then
|
|
||||||
if cb_message then
|
|
||||||
return false, cb_message
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- inform user
|
-- inform user
|
||||||
|
@ -45,7 +45,10 @@ beerchat.execute_callbacks = function(trigger, ...)
|
|||||||
for _,fn in ipairs(cb_list) do
|
for _,fn in ipairs(cb_list) do
|
||||||
local result, msg = fn(unpack(arg))
|
local result, msg = fn(unpack(arg))
|
||||||
if result ~= nil then
|
if result ~= nil then
|
||||||
return result, msg
|
if msg and type(arg[1]) == "string" then
|
||||||
|
minetest.chat_send_player(arg[1], msg)
|
||||||
|
end
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if trigger == 'before_check_muted' then
|
if trigger == 'before_check_muted' then
|
||||||
|
6
init.lua
6
init.lua
@ -79,13 +79,15 @@ beerchat.http = nil
|
|||||||
|
|
||||||
-- integrated extensions (could also be different mod)
|
-- integrated extensions (could also be different mod)
|
||||||
if minetest.settings:get_bool("beerchat.enable_jail") then
|
if minetest.settings:get_bool("beerchat.enable_jail") then
|
||||||
dofile(MP.."/jail.lua")
|
dofile(MP.."/plugin/jail.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.settings:get_bool("beerchat.enable_cleaner") then
|
if minetest.settings:get_bool("beerchat.enable_cleaner") then
|
||||||
dofile(MP.."/cleaner.lua")
|
dofile(MP.."/plugin/cleaner.lua")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dofile(MP.."/plugin/override.lua")
|
||||||
|
|
||||||
if minetest.settings:get_bool("enable_beerchat_integration_test") then
|
if minetest.settings:get_bool("enable_beerchat_integration_test") then
|
||||||
dofile(MP.."/integration_test.lua")
|
dofile(MP.."/integration_test.lua")
|
||||||
end
|
end
|
||||||
|
41
message.lua
41
message.lua
@ -16,36 +16,31 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
beerchat.send_on_channel = function(name, channel_name, message)
|
beerchat.send_on_channel = function(name, channel_name, message)
|
||||||
local msg_data = {name=name, channel=channel_name,message=message}
|
local msg = {name=name, channel=channel_name,message=message}
|
||||||
if beerchat.execute_callbacks('on_send_on_channel', msg_data) then
|
|
||||||
name = msg_data.name
|
|
||||||
channel_name = msg_data.channel_name
|
|
||||||
message = msg_data.message
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
local target = player:get_player_name()
|
local target = player:get_player_name()
|
||||||
-- Checking if the target is in this channel
|
-- Checking if the target is in this channel
|
||||||
if beerchat.is_player_subscribed_to_channel(target, channel_name) then
|
if beerchat.execute_callbacks('on_send_on_channel', msg, target) then
|
||||||
if not beerchat.has_player_muted_player(target, name) then
|
beerchat.send_message(
|
||||||
beerchat.send_message(
|
target,
|
||||||
target,
|
beerchat.format_message(
|
||||||
beerchat.format_message(
|
beerchat.main_channel_message_string, {
|
||||||
beerchat.main_channel_message_string, {
|
channel_name = msg.channel,
|
||||||
channel_name = channel_name,
|
to_player = target,
|
||||||
to_player = target,
|
from_player = msg.name,
|
||||||
from_player = name,
|
message = msg.message
|
||||||
message = message
|
}
|
||||||
}
|
),
|
||||||
),
|
msg.channel
|
||||||
channel_name
|
)
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
beerchat.register_callback("on_send_on_channel", function(msg, target)
|
||||||
|
return beerchat.is_player_subscribed_to_channel(target, msg.channel)
|
||||||
|
and not beerchat.has_player_muted_player(target, msg.name)
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.register_on_chat_message(function(name, message)
|
minetest.register_on_chat_message(function(name, message)
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
--luacheck: no_unused_args
|
||||||
|
|
||||||
-- Jail channel is where you put annoying missbehaving users with /force2channel
|
-- Jail channel is where you put annoying missbehaving users with /force2channel
|
||||||
beerchat.jail = {}
|
beerchat.jail = {}
|
||||||
|
|
||||||
@ -140,6 +142,9 @@ beerchat.register_callback('before_send', function(name, message, channel)
|
|||||||
-- override default send method to mute pings for jailed users
|
-- override default send method to mute pings for jailed users
|
||||||
-- but allow chatting without pings on jail channel
|
-- but allow chatting without pings on jail channel
|
||||||
minetest.chat_send_player(name, message)
|
minetest.chat_send_player(name, message)
|
||||||
|
else
|
||||||
|
-- Inform player if trying to send to other channels
|
||||||
|
return false, "You are in chat-jail, no changing channels for you."
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -147,7 +152,7 @@ end)
|
|||||||
|
|
||||||
beerchat.register_callback('before_switch_chan', function(name, oldchannel, newchannel)
|
beerchat.register_callback('before_switch_chan', function(name, oldchannel, newchannel)
|
||||||
if beerchat.is_player_jailed(name) then
|
if beerchat.is_player_jailed(name) then
|
||||||
return false
|
return false, "You are in chat-jail, no changing channels for you."
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -165,7 +170,7 @@ end)
|
|||||||
|
|
||||||
beerchat.register_callback('before_whisper', function(name, message, channel, range)
|
beerchat.register_callback('before_whisper', function(name, message, channel, range)
|
||||||
if beerchat.is_player_jailed(name) then
|
if beerchat.is_player_jailed(name) then
|
||||||
return false
|
return false, "You are in chat-jail, you may not whisper."
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
22
plugin/override.lua
Normal file
22
plugin/override.lua
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
--luacheck: globals minetest.registered_chatcommands.tell
|
||||||
|
|
||||||
|
minetest.register_on_mods_loaded(function()
|
||||||
|
|
||||||
|
-- Override /tell chat command to execute callbacks.
|
||||||
|
-- Command is added by mesecons command block.
|
||||||
|
if minetest.registered_chatcommands.tell then
|
||||||
|
local tell = minetest.registered_chatcommands.tell.func
|
||||||
|
minetest.registered_chatcommands.tell.func = function(name, param)
|
||||||
|
local target, message = param:match("^([^%s]+)%s+(.*)$")
|
||||||
|
local cb_result, cb_message = beerchat.execute_callbacks('before_send_pm', name, message, target)
|
||||||
|
if cb_result then
|
||||||
|
return tell(name, param)
|
||||||
|
end
|
||||||
|
if cb_message then
|
||||||
|
minetest.chat_send_player(name, cb_message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end)
|
10
pm.lua
10
pm.lua
@ -30,9 +30,8 @@ minetest.register_on_chat_message(function(name, message)
|
|||||||
if msg == "" then
|
if msg == "" then
|
||||||
minetest.chat_send_player(name, "Please enter the private message you would like to send")
|
minetest.chat_send_player(name, "Please enter the private message you would like to send")
|
||||||
else
|
else
|
||||||
local cb_result, cb_message = beerchat.execute_callbacks('before_send_pm', name, msg, players)
|
if not beerchat.execute_callbacks('before_send_pm', name, msg, players) then
|
||||||
if not cb_result then
|
return false
|
||||||
if cb_message then return false, cb_message else return false end
|
|
||||||
end
|
end
|
||||||
if players == "" then--reply
|
if players == "" then--reply
|
||||||
-- We need to get the target
|
-- We need to get the target
|
||||||
@ -182,9 +181,8 @@ local msg_override = {
|
|||||||
minetest.chat_send_player(name, "ERROR: Please enter the private message you would like to send")
|
minetest.chat_send_player(name, "ERROR: Please enter the private message you would like to send")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
local cb_result, cb_message = beerchat.execute_callbacks('before_send_pm', name, msg, players)
|
if not beerchat.execute_callbacks('before_send_pm', name, msg, players) then
|
||||||
if not cb_result then
|
return false
|
||||||
if cb_message then return false, cb_message else return false end
|
|
||||||
end
|
end
|
||||||
if players and players ~= "" then
|
if players and players ~= "" then
|
||||||
send_pm(players, name, msg)
|
send_pm(players, name, msg)
|
||||||
|
@ -32,10 +32,8 @@ beerchat.whisper = function(name, message)
|
|||||||
minetest.chat_send_player(name, "Please enter the message you would like to "
|
minetest.chat_send_player(name, "Please enter the message you would like to "
|
||||||
.. "whisper to nearby players")
|
.. "whisper to nearby players")
|
||||||
else
|
else
|
||||||
local cb_result, cb_message = beerchat.execute_callbacks('before_whisper',
|
if not beerchat.execute_callbacks('before_whisper', name, msg, beerchat.main_channel_name, radius) then
|
||||||
name, msg, beerchat.main_channel_name, radius)
|
return false
|
||||||
if not cb_result then
|
|
||||||
if cb_message then return false, cb_message else return false end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- true if someone heard the player
|
-- true if someone heard the player
|
||||||
|
Loading…
x
Reference in New Issue
Block a user