forked from MTSR/telegram
Added ability to announce player joining or leaving, including none, privileged or all
This commit is contained in:
parent
bf832e684c
commit
c404aee07c
6
README.md
Normal file
6
README.md
Normal file
@ -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.
|
||||
|
25
init.lua
25
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")
|
||||
|
Loading…
Reference in New Issue
Block a user