Move join/leave/chat messages to mod instead of parsing stderr

This commit is contained in:
Ceda EI 2019-01-29 09:57:16 +05:30
parent bb9a9f7a9b
commit 7bdebb7fd3
2 changed files with 20 additions and 21 deletions

View File

@ -1,28 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from telegram import Bot
import sys import sys
import re import re
import config
from emoji import emojize
bot = Bot(token=config.api_key)
for line in sys.stdin: for line in sys.stdin:
text = ""
parse_mode = None
if not re.match(".* Mod performs HTTP request with URL ", line): if not re.match(".* Mod performs HTTP request with URL ", line):
print(line, end="") print(line, end="")
if re.match(r".*ACTION\[Server\]: CHAT", line):
text = re.sub(".*?CHAT: ", "", line)
elif re.match(r".*?(\w+ (leaves|joins) game.*)", line):
text = "<code>"
text += re.sub(r".*?(\w+ (leaves|joins) game\.).*", r"\1", line)
text += "</code>"
parse_mode = "HTML"
if text != "":
print(text)
for i in config.groups:
if parse_mode:
bot.send_message(chat_id=i, text=emojize(text),
parse_mode=parse_mode)
else:
bot.send_message(chat_id=i, text=emojize(text))

View File

@ -36,9 +36,29 @@ function dead(player)
" died."}}) " died."}})
end end
function join(player)
http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode",
post_data = {message = player.get_player_name(player) ..
" joined the server."}})
end
function left(player)
http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode",
post_data = {message = player.get_player_name(player) ..
" left the server."}})
end
function chat(name, message)
http_api.fetch_async({url = "http://localhost:" .. port .. "/send",
post_data = {message = "<" .. name .. "> " .. message}})
end
if http_api == nil then if http_api == nil then
minetest.log("error", "Chat Mod is not in secure.http_mods or secure.trusted_mods. Exiting.") minetest.log("error", "Chat Mod is not in secure.http_mods or secure.trusted_mods. Exiting.")
else else
main() main()
end end
minetest.register_on_dieplayer(dead) minetest.register_on_dieplayer(dead)
minetest.register_on_joinplayer(join)
minetest.register_on_leaveplayer(left)
minetest.register_on_chat_message(chat)