1
0
forked from MTSR/telegram

Compare commits

...

4 Commits

2 changed files with 64 additions and 1 deletions

42
.gitignore vendored Normal file
View File

@ -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

View File

@ -10,7 +10,7 @@ telegram = {}
local token = minetest.settings:get("telegram.token") local token = minetest.settings:get("telegram.token")
local chat_id = minetest.settings:get("telegram.chatid") local chat_id = minetest.settings:get("telegram.chatid")
local updates_timeout = tonumber(minetest.settings:get("telegram.timeout")) 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 if not updates_timeout then
updates_timeout = 1 updates_timeout = 1
@ -121,6 +121,18 @@ function telegram.on_text_receive(msg)
if command then if command then
command(msg) command(msg)
else 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 local message_text = msg.text
if msg.reply_to_message and msg.reply_to_message.text then if msg.reply_to_message and msg.reply_to_message.text then
message_text = ">>" .. msg.reply_to_message.text .. "\n" .. message_text message_text = ">>" .. msg.reply_to_message.text .. "\n" .. message_text
@ -165,7 +177,9 @@ end)
-- Don't send messages from MT to telegram if we don't know where to -- Don't send messages from MT to telegram if we don't know where to
if chat_id then if chat_id then
minetest.register_on_chat_message(function(name, message) minetest.register_on_chat_message(function(name, message)
if minetest.check_player_privs(name, {shout=true}) then
telegram.send_message(chat_id, "<" .. name .. "> " .. message) telegram.send_message(chat_id, "<" .. name .. "> " .. message)
end
return false return false
end) end)
@ -185,5 +199,12 @@ if chat_id then
end) end)
end end
end end
minetest.register_on_mods_loaded(function()
telegram.send_message(chat_id, "The server has started")
end)
minetest.register_on_shutdown(function()
telegram.send_message(chat_id, "Server shutdown")
end)
dofile(modpath .. "/commands.lua") dofile(modpath .. "/commands.lua")