beerchat/message.lua

92 lines
3.2 KiB
Lua
Raw Normal View History

2019-08-04 23:33:20 -07:00
-- Message string formats -- Change these if you would like different formatting
--
-- These can be changed to show "~~~#mychannel~~~ <player01> message" instead of "|#mychannel| or any
-- other format you like such as removing the channel name from the main channel, putting channel or
-- player names at the end of the chat message, etc.
--
-- The following parameters are available and can be specified :
-- ${channel_name} name of the channel
-- ${channel_owner} owner of the channel
-- ${channel_password} password to use when joining the channel, used e.g. for invites
-- ${from_player} the player that is sending the message
2019-08-05 00:00:27 -07:00
-- ${to_player} player to which the message is sent, will contain multiple player names
-- e.g. when sending a PM to multiple players
2019-08-04 23:33:20 -07:00
-- ${message} the actual message that is to be sent
-- ${time} the current time in 24 hour format, as returned from os.date("%X")
--
2019-09-03 02:17:58 -07:00
beerchat.send_on_channel = function(name, channel_name, message)
2021-01-18 05:01:41 -08:00
local msg_data = {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
2019-09-03 02:17:58 -07:00
for _,player in ipairs(minetest.get_connected_players()) do
local target = player:get_player_name()
-- Checking if the target is in this channel
2019-11-12 09:37:39 -08:00
if beerchat.is_player_subscribed_to_channel(target, channel_name) then
if not beerchat.has_player_muted_player(target, name) then
beerchat.send_message(
2019-09-03 02:17:58 -07:00
target,
beerchat.format_message(
beerchat.main_channel_message_string, {
channel_name = channel_name,
to_player = target,
from_player = name,
message = message
}
2019-11-12 09:37:39 -08:00
),
channel_name
2019-09-03 02:17:58 -07:00
)
end
end
end
end
2019-08-04 23:33:20 -07:00
minetest.register_on_chat_message(function(name, message)
local msg_data = {name=name,message=message}
if beerchat.execute_callbacks('on_receive', msg_data) then
message = msg_data.message
else
return false
end
2019-08-04 23:33:20 -07:00
local channel_name = beerchat.currentPlayerChannel[name]
if not minetest.check_player_privs(name, "shout") then
-- the player does not have the shout priv, skip processing to channels
return false -- mark as "not handled"
end
2019-08-04 23:33:20 -07:00
if not beerchat.channels[channel_name] then
2019-08-05 00:00:27 -07:00
minetest.chat_send_player(
name,
"Channel "..channel_name.." does not exist, switching back to "..
beerchat.main_channel_name..". Please resend your message"
)
2019-08-04 23:33:20 -07:00
beerchat.currentPlayerChannel[name] = beerchat.main_channel_name
2019-11-12 09:37:39 -08:00
minetest.get_player_by_name(name):get_meta():set_string(
"beerchat:current_channel", beerchat.main_channel_name)
2019-08-04 23:33:20 -07:00
return true
end
if not beerchat.channels[channel_name] then
minetest.chat_send_player(name, "Channel "..channel_name.." does not exist")
2019-09-03 02:17:58 -07:00
elseif message == "" then
2019-11-12 09:37:39 -08:00
minetest.chat_send_player(name,
"Please enter the message you would like to send to the channel")
elseif not beerchat.is_player_subscribed_to_channel(name, channel_name) then
minetest.chat_send_player(name,
"You need to join this channel in order to be able to send messages to it")
2019-08-04 23:33:20 -07:00
else
beerchat.on_channel_message(channel_name, name, message)
2019-09-03 02:17:58 -07:00
beerchat.send_on_channel(name, channel_name, message)
2019-08-04 23:33:20 -07:00
end
return true
end)