Add pipe_in.py to deal with minetest output

This commit is contained in:
Ceda EI 2019-01-28 17:49:06 +05:30
parent a5ed267b32
commit 2d377081b6
1 changed files with 30 additions and 0 deletions

30
bot/pipe_in.py Executable file
View File

@ -0,0 +1,30 @@
#!/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 += "\nList of players: \n"
text += "\n".join(re.sub(r".*?: ", "", line).split(" "))
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))