Change reply format. Demojize
This commit is contained in:
parent
e075c24306
commit
a5ed267b32
15
bot/bot.py
15
bot/bot.py
|
@ -4,6 +4,7 @@ import config
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
|
from emoji import demojize
|
||||||
from telegram.ext import Updater, MessageHandler, Filters
|
from telegram.ext import Updater, MessageHandler, Filters
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \
|
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('(<.*?>)(.*)')
|
x = re.compile('(<.*?>)(.*)')
|
||||||
y = x.search(msg.text)
|
y = x.search(msg.text)
|
||||||
z = y.group(2)
|
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:
|
else:
|
||||||
message += (msg.text if len(msg.text) <= 10 or not truncate else
|
message += (msg.text if len(msg.text) <= 20 or not truncate else
|
||||||
msg.text[0:9] + "...")
|
msg.text[0:19] + "...")
|
||||||
elif msg.audio:
|
elif msg.audio:
|
||||||
message += "[Audio]"
|
message += "[Audio]"
|
||||||
elif msg.document:
|
elif msg.document:
|
||||||
|
@ -52,8 +53,8 @@ def get_text_or_type(msg, bot, truncate=False):
|
||||||
|
|
||||||
# If caption exists
|
# If caption exists
|
||||||
if msg.caption:
|
if msg.caption:
|
||||||
message += (msg.caption if len(msg.caption) <= 10 or not truncate else
|
message += (msg.caption if len(msg.caption) <= 20 or not truncate else
|
||||||
msg.caption[0:9] + "...")
|
msg.caption[0:19] + "...")
|
||||||
|
|
||||||
# Set sender
|
# Set sender
|
||||||
return_message = ""
|
return_message = ""
|
||||||
|
@ -69,7 +70,7 @@ def get_text_or_type(msg, bot, truncate=False):
|
||||||
return_message = y.group(1) + ": " + i + "\n"
|
return_message = y.group(1) + ": " + i + "\n"
|
||||||
# Set the replied to message's contents
|
# Set the replied to message's contents
|
||||||
if msg.reply_to_message:
|
if msg.reply_to_message:
|
||||||
return_message += ("[Reply to " +
|
return_message += ("[> " +
|
||||||
get_text_or_type(msg.reply_to_message, bot,
|
get_text_or_type(msg.reply_to_message, bot,
|
||||||
True).split("\n")[0] +
|
True).split("\n")[0] +
|
||||||
f"] ")
|
f"] ")
|
||||||
|
@ -81,7 +82,7 @@ def get_text_or_type(msg, bot, truncate=False):
|
||||||
def message_handling(bot, update):
|
def message_handling(bot, update):
|
||||||
if update.message.chat.id in config.groups:
|
if update.message.chat.id in config.groups:
|
||||||
message = get_text_or_type(update.message, bot)
|
message = get_text_or_type(update.message, bot)
|
||||||
params = {"message": message}
|
params = {"message": demojize(message)}
|
||||||
requests.post("http://localhost:" + str(config.port) + "/post",
|
requests.post("http://localhost:" + str(config.port) + "/post",
|
||||||
data=params)
|
data=params)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue