Move join/leave/chat messages to mod instead of parsing stderr
This commit is contained in:
parent
bb9a9f7a9b
commit
7bdebb7fd3
|
@ -1,28 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
from telegram import Bot
|
||||
import sys
|
||||
import re
|
||||
import config
|
||||
from emoji import emojize
|
||||
|
||||
bot = Bot(token=config.api_key)
|
||||
for line in sys.stdin:
|
||||
text = ""
|
||||
parse_mode = None
|
||||
if not re.match(".* Mod performs HTTP request with URL ", line):
|
||||
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))
|
||||
|
|
|
@ -36,9 +36,29 @@ function dead(player)
|
|||
" died."}})
|
||||
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
|
||||
minetest.log("error", "Chat Mod is not in secure.http_mods or secure.trusted_mods. Exiting.")
|
||||
else
|
||||
main()
|
||||
end
|
||||
minetest.register_on_dieplayer(dead)
|
||||
minetest.register_on_joinplayer(join)
|
||||
minetest.register_on_leaveplayer(left)
|
||||
minetest.register_on_chat_message(chat)
|
||||
|
|
Loading…
Reference in New Issue