From c404aee07cd4be2e4b9bffac7efcb5b0e7e7d243 Mon Sep 17 00:00:00 2001 From: neko259 Date: Tue, 5 Feb 2019 16:49:42 +0200 Subject: [PATCH] Added ability to announce player joining or leaving, including none, privileged or all --- README.md | 6 ++++++ init.lua | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..6f15bd9 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ += Available configurations (add to minetest.conf) = +* telegram.token -- requred, bot token aquired for your bot in telegram +* telegram.chatid -- id of the chat you will relay messages to. You can start the bot without it and send groupid command to get it later. +* telegram.timeout -- update periodicity. The bot does check for the new messages with this timeout, but the in-game messages are sent to telegram immediately. Increase for better performance. +* telegram.announce_mode -- announce player joining or leaving. Available options: none, privileged, all. Priviliged means interact for now. Player deaths may be announced in the future, but not yet. + diff --git a/init.lua b/init.lua index a083420..197231e 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,10 @@ local current_mod_name = minetest.get_current_modname() local modpath = minetest.get_modpath(current_mod_name) +local ANNOUNCE_NONE = "none" +local ANNOUNCE_PRIVILEGED = "privileged" +local ANNOUNCE_ALL = "all" + telegram = {} local token = minetest.settings:get("telegram.token") @@ -11,6 +15,11 @@ if not updates_timeout then updates_timeout = 1 end +local announce_mode = minetest.settings:get("telegram.announce_mode") +if not announce_mode then + announce_mode = ANNOUNCE_NONE +end + if not token then error("Bot token should be specified in the config in order to work.") end @@ -157,6 +166,22 @@ if chat_id then telegram.send_message(chat_id, "<" .. name .. "@MT> " .. message) return false end) + + if announce_mode ~= ANNOUNCE_NONE then + minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + if announce_mode == ANNOUNCE_ALL or minetest.check_player_privs(name, "interact") then + telegram.send_message(chat_id, name .. " joined the game.") + end + end) + + minetest.register_on_leaveplayer(function(player, timed_out) + local name = player:get_player_name() + if announce_mode == ANNOUNCE_ALL or minetest.check_player_privs(name, "interact") then + telegram.send_message(chat_id, name .. " left the game.") + end + end) + end end dofile(modpath .. "/commands.lua")