fix template replace

This commit is contained in:
2024-05-13 00:00:08 +08:00
parent e629899a72
commit a1d1dc5ea3
+8 -8
View File
@@ -91,16 +91,16 @@ async def edit_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
return return
template = context.user_data.get('template', None) template = context.user_data.get('template', None)
if template: if template:
update_text = template update_text = template.replace("[]", html.escape(update.message.text))
else: else:
update_text = html.escape(update.message.text) update_text = html.escape(update.message.text)
match = common.message_url_regex.search(update_text) match = common.message_url_regex.search(update_text)
if match: if match:
match = match.span() match = match.span()
update_text = update_text[:match[0]] + '<a href="{0}">{1}</a>'.format( update_text = update_text[:match[0]] + '<a href="{0}">{1}</a>'.format(
context.user_data['message_url'], context.user_data['message_url'],
update_text[match[0] + 1:match[1] - 1] if not template else update.message.text update_text[match[0] + 1:match[1] - 1]
) + update_text[match[1]:] ) + update_text[match[1]:]
message_to_send = context.user_data['message_to_send'] message_to_send = context.user_data['message_to_send']
await message_to_send[0].edit_caption(update_text) await message_to_send[0].edit_caption(update_text)