From a1d1dc5ea37b5260e4cf57f5d74937d8e047ab0c Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Mon, 13 May 2024 00:00:08 +0800 Subject: [PATCH] fix template replace --- main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 7db0970..7cf61ed 100644 --- a/main.py +++ b/main.py @@ -91,16 +91,16 @@ async def edit_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No return template = context.user_data.get('template', None) if template: - update_text = template + update_text = template.replace("[]", html.escape(update.message.text)) else: update_text = html.escape(update.message.text) - match = common.message_url_regex.search(update_text) - if match: - match = match.span() - update_text = update_text[:match[0]] + '{1}'.format( - context.user_data['message_url'], - update_text[match[0] + 1:match[1] - 1] if not template else update.message.text - ) + update_text[match[1]:] + match = common.message_url_regex.search(update_text) + if match: + match = match.span() + update_text = update_text[:match[0]] + '{1}'.format( + context.user_data['message_url'], + update_text[match[0] + 1:match[1] - 1] + ) + update_text[match[1]:] message_to_send = context.user_data['message_to_send'] await message_to_send[0].edit_caption(update_text)