From 7bdebb7fd3b2c3ee8c3fb7be2e4bd9cd5717bbfe Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 29 Jan 2019 09:57:16 +0530 Subject: [PATCH] Move join/leave/chat messages to mod instead of parsing stderr --- bot/pipe_in.py | 21 --------------------- chat_mod/init.lua | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/bot/pipe_in.py b/bot/pipe_in.py index b23e5d3..b97a22f 100755 --- a/bot/pipe_in.py +++ b/bot/pipe_in.py @@ -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 = "" - text += re.sub(r".*?(\w+ (leaves|joins) game\.).*", r"\1", line) - 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)) diff --git a/chat_mod/init.lua b/chat_mod/init.lua index fb530d4..6912628 100644 --- a/chat_mod/init.lua +++ b/chat_mod/init.lua @@ -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)