minetest-telegram-bridge/bot/pipe_in.py

31 lines
1011 B
Python
Executable File

#!/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))