atchat/init.lua

41 lines
1.3 KiB
Lua
Executable File

--comments have not been removed
--[[ All code around the messaging system should be kept here. ]]--
atchat_lastrecv = {}
--now: new stuff: register_on_chat_message
minetest.register_on_chat_message(function(name, message)
local players, msg=string.match(message, "^@([^%s:]*)[%s:](.*)")
if players and msg then
if msg == "" then
minetest.chat_send_player(name, "You have to say something!")
else
if players=="" then--reply
-- We need to get the target
players = atchat_lastrecv[name]
end
if players and players ~= "" then
local sent_to_any
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
-- Sending the message
minetest.chat_send_player(target, string.format("(%s) %s", name, msg))
sent_to_any = true
end
end
if sent_to_any then
-- Register the chat in the target persons lastspoke tabler
atchat_lastrecv[name] = players
-- echo back to sender
minetest.chat_send_player(name, string.format("(@%s) %s", players, msg))
end
else
minetest.chat_send_player(name, "Nobody you've spoken to yet!")
end
end
return true
end
end)