From 2d377081b63a5d4f8317c0b8aff1b9ef031a8d1e Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Mon, 28 Jan 2019 17:49:06 +0530 Subject: [PATCH] Add pipe_in.py to deal with minetest output --- bot/pipe_in.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 bot/pipe_in.py diff --git a/bot/pipe_in.py b/bot/pipe_in.py new file mode 100755 index 0000000..7f32480 --- /dev/null +++ b/bot/pipe_in.py @@ -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 = "" + 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 += "" + 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))