From 1000540ef9b654d123bc8ffcef3d0b7a8376ccb5 Mon Sep 17 00:00:00 2001 From: Vitaliy Olkhin Date: Thu, 10 Oct 2024 13:14:59 +0500 Subject: [PATCH] Added filtering of messages by chat topic --- .gitignore | 42 ++++++++++++++++++++++++++++++++++++++++++ init.lua | 14 +++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..20ab12d --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# Compiled Lua sources +luac.out + +# luarocks build files +*.src.rock +*.zip +*.tar.gz + +# Object files +*.o +*.os +*.ko +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo +*.def +*.exp + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex +.idea +*.iml + diff --git a/init.lua b/init.lua index eaa8258..970cb62 100644 --- a/init.lua +++ b/init.lua @@ -10,7 +10,7 @@ telegram = {} local token = minetest.settings:get("telegram.token") local chat_id = minetest.settings:get("telegram.chatid") local updates_timeout = tonumber(minetest.settings:get("telegram.timeout")) -local message_thread_id = minetest.settings:get("telegram.message_thread_id") +local message_thread_id = tonumber(minetest.settings:get("telegram.message_thread_id")) if not updates_timeout then updates_timeout = 1 @@ -121,6 +121,18 @@ function telegram.on_text_receive(msg) if command then command(msg) else + if message_thread_id then + if msg.message_thread_id == nil then + minetest.log("action", "telegram: message_thread_id not equal 'nil'") + return + end + + if msg.message_thread_id ~= message_thread_id then + minetest.log("action", "telegram: message_thread_id not equal " .. msg.message_thread_id) + return + end + end + local message_text = msg.text if msg.reply_to_message and msg.reply_to_message.text then message_text = ">>" .. msg.reply_to_message.text .. "\n" .. message_text