Changed markdown to html
This commit is contained in:
@@ -77,7 +77,7 @@ def get_winners(raffle_id, winner_numbers_int):
|
||||
continue
|
||||
|
||||
user_id = participant['user_id']
|
||||
user_name = escape_markdown_v2_chars_for_username(participant['user_name']) or f"User_{user_id}" # Fallback name
|
||||
user_name = participant['user_name'] or f"User_{user_id}" # Fallback name
|
||||
numbers_str = participant['numbers']
|
||||
|
||||
try:
|
||||
@@ -104,7 +104,7 @@ def get_winners(raffle_id, winner_numbers_int):
|
||||
for user_name, numbers in winners.items():
|
||||
# Ensure numbers are unique in the final output per user
|
||||
unique_numbers_str = ", ".join(sorted(list(set(numbers))))
|
||||
winners_message_parts.append(f"- @{escape_markdown_v2_chars_for_username(user_name)} acertó: **{unique_numbers_str}**")
|
||||
winners_message_parts.append(f"- @{user_name} acertó: <b>{unique_numbers_str}</b>")
|
||||
|
||||
return "\n".join(winners_message_parts)
|
||||
|
||||
@@ -371,22 +371,6 @@ def generate_table_image(raffle_id):
|
||||
img.save(image_path)
|
||||
return True
|
||||
|
||||
|
||||
def escape_markdown_v2_chars_for_username(text: str) -> str:
|
||||
"""Escapes characters for MarkdownV2, specifically for usernames."""
|
||||
# For usernames, usually only _ and * are problematic if not part of actual formatting
|
||||
# Other MarkdownV2 special characters: `[` `]` `(` `)` `~` `>` `#` `+` `-` `=` `|` `{` `}` `.` `!`
|
||||
# We are most concerned with _ in @user_name context.
|
||||
# A more comprehensive list of characters to escape for general text:
|
||||
# escape_chars = r'_*[]()~`>#+-=|{}.!'
|
||||
# For just usernames in this context, focus on what breaks @user_name
|
||||
escape_chars = r'_*`[' # Adding ` and [ just in case they appear in odd usernames
|
||||
|
||||
# Python's re.escape escapes all non-alphanumerics.
|
||||
# We only want to escape specific markdown control characters within the username.
|
||||
# For usernames, simply escaping '_' is often enough for the @mention issue.
|
||||
return "".join(['\\' + char if char in escape_chars else char for char in text])
|
||||
|
||||
def format_last_participants_list(participants_list: list) -> str:
|
||||
"""
|
||||
Formats the list of last participants for the announcement message.
|
||||
@@ -405,9 +389,9 @@ def format_last_participants_list(participants_list: list) -> str:
|
||||
if numbers_str:
|
||||
num_list = numbers_str.split(',')
|
||||
if len(num_list) == 1:
|
||||
line = f" - {escape_markdown_v2_chars_for_username(user_name)}, con la papeleta: {num_list[0]}"
|
||||
line = f" - {user_name}, con la papeleta: {num_list[0]}"
|
||||
else:
|
||||
line = f" - {escape_markdown_v2_chars_for_username(user_name)}, con las papeletas: {', '.join(num_list)}"
|
||||
line = f" - {user_name}, con las papeletas: {', '.join(num_list)}"
|
||||
formatted_lines.append(line)
|
||||
|
||||
return "\n".join(formatted_lines) # Add a trailing newline
|
||||
|
||||
Reference in New Issue
Block a user