From ba3ae4420dbcbc480622f13f81913153990bc6bc Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Sun, 12 Jun 2022 18:00:13 +0200 Subject: [PATCH] chat --- .luacheckrc | 4 ++-- handlers/chat.lua | 31 +++++++++++++++++++++++++++++++ init.lua | 1 + 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 handlers/chat.lua diff --git a/.luacheckrc b/.luacheckrc index 55c1e29..d881ff7 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,5 +1,6 @@ globals = { - "mtui" + "mtui", + "minetest" } read_globals = { @@ -8,7 +9,6 @@ read_globals = { table = {fields = {"copy", "getn"}}, -- Minetest - "minetest", "vector", "ItemStack", "dump", "dump2", "VoxelArea" diff --git a/handlers/chat.lua b/handlers/chat.lua new file mode 100644 index 0000000..96442f6 --- /dev/null +++ b/handlers/chat.lua @@ -0,0 +1,31 @@ + + +local old_chat_send_all = minetest.chat_send_all +local old_chat_send_player = minetest.chat_send_player + +-- message/PM from the ui to ingame +mtui.register_on_command("send_chat_message", function(data) + old_chat_send_player(data.name, "DM from " .. data.name .. ": " .. data.text) +end) + +-- intercept ingame message and send themto the ui +function minetest.chat_send_player(name, text) + old_chat_send_player(name, text) + mtui.send_command({ + type = "chat_send_player", + data = { + name = name, + text = text + } + }) +end + +function minetest.chat_send_all(text) + old_chat_send_all(text) + mtui.send_command({ + type = "chat_send_all", + data = { + text = text + } + }) +end \ No newline at end of file diff --git a/init.lua b/init.lua index ff613e9..a352f75 100644 --- a/init.lua +++ b/init.lua @@ -17,4 +17,5 @@ loadfile(MP.."/bridge_tx.lua")(http) dofile(MP.."/tan.lua") dofile(MP.."/stats.lua") dofile(MP.."/handlers/ping.lua") +dofile(MP.."/handlers/chat.lua") dofile(MP.."/handlers/execute_command.lua")