~mendelmaleh/tg_translator

382ecc1cf1c678afc75009f6287e9d03878454be — Mendel E 1 year, 6 months ago 6ab184f master
Add replied to link
1 files changed, 16 insertions(+), 2 deletions(-)

M main.py
M main.py => main.py +16 -2
@@ 1,3 1,5 @@
import html

import googletrans
import toml



@@ 19,11 21,23 @@ bot = Client("bot", api_id, api_hash, bot_token=config["bot"]["token"])
async def translate(cl: Client, msg: Message):
    if not (msg.text or msg.caption):
        return
    text = tr.translate(msg.text or msg.caption).text

    translated = tr.translate(msg.text or msg.caption)
    text = msg.link

    if msg.reply_to_message:
        text += f" (<a href=\"{msg.reply_to_message.link}\">replied to</a>)"

    if msg.edit_date:
        text += " (edited)"

    text += "\n\n"
    text += html.escape(translated.text)

    await bot.send_message(
        chat_id=channels[msg.chat.id],
        text=f"{msg.link}{' (edited)' if msg.edit_date else ''}\n\n{text}",
        text=text,
        parse_mode="html",
        disable_web_page_preview=bool(msg.text),
        disable_notification=bool(msg.edit_date)
    )