aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-04-22 23:59:12 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-04-22 23:59:12 +0200
commit9209cf394656fe2179f824dda72700cd382f373f (patch)
tree7b20e3d4d06208ec2d84d2b34a50941e04f0526d
parent021bc875b4f3e1301fec2de32e52911fdf65215c (diff)
downloadbeerchat-master.tar.gz
beerchat-master.tar.bz2
beerchat-master.zip
Rework direct message system, pms can be sent to multiple people now.HEADmaster
-rw-r--r--init.lua72
1 files changed, 17 insertions, 55 deletions
diff --git a/init.lua b/init.lua
index 0c400aa..2d72304 100644
--- a/init.lua
+++ b/init.lua
@@ -47,9 +47,9 @@ local channel_deleted_string = channel_prefix.."Channel deleted"
local channel_joined_string = channel_prefix.."Joined channel"
local channel_left_string = channel_prefix.."Left channel"
local channel_already_deleted_string = channel_prefix.."Channel seems to have already been deleted, will unregister channel from your list of channels"
-local private_message_string = "[PM] from (${from_player}) ${message}"
+local private_message_string = "[DM] from (${from_player}) ${message}"
local self_message_string = "(${from_player} utters to him/ herself) ${message}"
-local private_message_sent_string = "[PM] sent to @(${to_player}) ${message}"
+local private_message_sent_string = "[DM] sent to @(${to_player}) ${message}"
local me_message_string = "* ${from_player} ${message}"
local message_string = "<${from_player}> ${message}"
local whisper_string = "<${from_player}> whispers: ${message}"
@@ -157,6 +157,7 @@ beerchat.get_current_channel = function(pname)
return channel_name
end
+
minetest.register_on_joinplayer(function(player)
local str = player:get_attribute("beerchat:channels")
if str and str ~= "" then
@@ -504,12 +505,10 @@ minetest.register_chatcommand("unignore", unmute_player)
-- @ chat a.k.a. at chat/ PM chat code, to PM players using @player1 only you can read this player1!!
atchat_lastrecv = {}
-minetest.register_on_chat_message(function(name, message)
- local raw_msg = minetest.strip_colors(message)
- local players, msg = string.match(raw_msg, "^@([^%s:]*)[%s:](.*)")
+beerchat.send_pm = function(name, players, msg)
if players and 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 direct message you would like to send")
else
if players == "" then--reply
-- We need to get the target
@@ -518,7 +517,7 @@ minetest.register_on_chat_message(function(name, message)
if players and players ~= "" then
local atleastonesent = false
local successplayers = ""
- for target in string.gmatch(","..players..",", ",([^,]+),") do
+ for target in string.gmatch(players..",", "([^,]+),") do
-- Checking if the target exists
if not minetest.get_player_by_name(target) then
minetest.chat_send_player(name, ""..target.." is not online")
@@ -545,70 +544,33 @@ minetest.register_on_chat_message(function(name, message)
atchat_lastrecv[name] = players
if atleastonesent then
successplayers = successplayers:sub(1, -2)
+ beerchat.log("DM", "from "..name.." sent to @("..successplayers.."): "..msg)
if (successplayers ~= name) then
minetest.chat_send_player(name, format_message(private_message_sent_string, { to_player = successplayers, message = msg }))
end
end
else
- minetest.chat_send_player(name, "You have not sent private messages to anyone yet, please specify player names to send message to")
+ minetest.chat_send_player(name, "You have not sent direct messages to anyone yet, please specify player names to send message to")
end
end
return true
end
+end
+
+minetest.register_on_chat_message(function(name, message)
+ local raw_msg = minetest.strip_colors(message)
+ local players, msg = string.match(raw_msg, "^@([^%s:]*)[%s:](.*)")
+ return beerchat.send_pm(name,players,msg)
end)
local msg_override = {
params = "<Player Name> <Message>",
- description = "Send private message to player, for compatibility with the old chat command but with new style chat muting support "..
+ description = "Send direct message to player, for compatibility with the old chat command but with new style chat muting support "..
"(players will not receive your message if they muted you) and multiple (comma separated) player support",
func = function(name, param)
local players, msg = string.match(param, "^(.-) (.*)")
- if players and msg then
- if players == "" then
- minetest.chat_send_player(name, "ERROR: Please enter the private message you would like to send")
- return false
- elseif msg == "" then
- minetest.chat_send_player(name, "ERROR: Please enter the private message you would like to send")
- return false
- else
- if players and players ~= "" then
- local atleastonesent = false
- local successplayers = ""
- for target in string.gmatch(","..players..",", ",([^,]+),") do
- -- Checking if the target exists
- if not minetest.get_player_by_name(target) then
- minetest.chat_send_player(name, ""..target.." is not online")
- else
- if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
- if target ~= name then
- -- Sending the message
- minetest.chat_send_player(target, format_message(private_message_string, { from_player = name, message = msg }))
- if enable_sounds then
- minetest.sound_play(private_message_sound, { to_player = target, gain = 1.0 } )
- end
- else
- minetest.chat_send_player(target, format_message(self_message_string, { from_player = name, message = msg }))
- if enable_sounds then
- minetest.sound_play(self_message_sound, { to_player = target, gain = 1.0 } )
- end
- end
- end
- atleastonesent = true
- successplayers = successplayers..target..","
- end
- end
- -- Register the chat in the target persons last spoken to table
- atchat_lastrecv[name] = players
- if atleastonesent then
- successplayers = successplayers:sub(1, -2)
- if (successplayers ~= name) then
- minetest.chat_send_player(name, format_message(private_message_sent_string, { to_player = successplayers, message = msg }))
- end
- end
- end
- end
- return true
- end
+ beerchat.send_pm(name,players,msg)
+ return true
end
}