From a5ed267b327c7eab43cfce971697b115bb4f2329 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Mon, 28 Jan 2019 17:18:15 +0530 Subject: [PATCH] Change reply format. Demojize --- bot/bot.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 9bd184e..d6b6f22 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -4,6 +4,7 @@ import config import logging import requests import re +from emoji import demojize from telegram.ext import Updater, MessageHandler, Filters logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \ @@ -19,10 +20,10 @@ def get_text_or_type(msg, bot, truncate=False): x = re.compile('(<.*?>)(.*)') y = x.search(msg.text) z = y.group(2) - message += (z if len(z) <= 10 or not truncate else z[0:9] + "...") + message += (z if len(z) <= 20 or not truncate else z[0:19] + "...") else: - message += (msg.text if len(msg.text) <= 10 or not truncate else - msg.text[0:9] + "...") + message += (msg.text if len(msg.text) <= 20 or not truncate else + msg.text[0:19] + "...") elif msg.audio: message += "[Audio]" elif msg.document: @@ -52,8 +53,8 @@ def get_text_or_type(msg, bot, truncate=False): # If caption exists if msg.caption: - message += (msg.caption if len(msg.caption) <= 10 or not truncate else - msg.caption[0:9] + "...") + message += (msg.caption if len(msg.caption) <= 20 or not truncate else + msg.caption[0:19] + "...") # Set sender return_message = "" @@ -69,7 +70,7 @@ def get_text_or_type(msg, bot, truncate=False): return_message = y.group(1) + ": " + i + "\n" # Set the replied to message's contents if msg.reply_to_message: - return_message += ("[Reply to " + + return_message += ("[> " + get_text_or_type(msg.reply_to_message, bot, True).split("\n")[0] + f"] ") @@ -81,7 +82,7 @@ def get_text_or_type(msg, bot, truncate=False): def message_handling(bot, update): if update.message.chat.id in config.groups: message = get_text_or_type(update.message, bot) - params = {"message": message} + params = {"message": demojize(message)} requests.post("http://localhost:" + str(config.port) + "/post", data=params)