commit 60d38b563f3cb7f15196ff54765a972b9e5acad7
parent decfcee160d4a92f4ceb06ef5306f707762e6427
Author: Byron Torres <b@torresjrjr.com>
Date: Sun, 28 Mar 2021 23:19:14 +0100
Convert TEMPLATE to use ParseMode.HTML
When TEMPLATE used ParseMode.MARKDOWN, Telegram would fail to parse
links with underscores. The previous commit quickfixed it.
Addresses #3, #4
Diffstat:
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/linkchanbot b/linkchanbot
@@ -38,7 +38,7 @@ VERSION = "1.0.0"
TEMPLATE = """
{new}
-[source]({old})
+<a href="{old}">source</a>
"""
EXAMPLES = {
@@ -512,9 +512,8 @@ def cb_link_handler(upd, ctx):
for oldlink, newlink in zip(oldlinks, newlinks):
logging.info(mk_status(upd, 'out', '::', f"{newlink}"))
- newlink = newlink.replace('_', '\\_')
msg = TEMPLATE.format(new=newlink, old=oldlink)
- upd.message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
+ upd.message.reply_text(msg, parse_mode=ParseMode.HTML)
@logger
@@ -561,10 +560,8 @@ def cb_inline_query(upd, ctx):
description = alt['description'],
thumb_url = alt['thumb_url'],
input_message_content = InputTextMessageContent(
- TEMPLATE.format(
- new=newlink.replace('_', '\\_'), old=query
- ),
- parse_mode=ParseMode.MARKDOWN,
+ TEMPLATE.format(new=newlink, old=query),
+ parse_mode=ParseMode.HTML,
)
) \
for newlink, alt in random.sample(