feat(discord): proteger menciones y mejorar traducción HTML para mensajes multilínea
This commit is contained in:
@@ -77,17 +77,21 @@ async def on_message(message):
|
||||
if not active_langs:
|
||||
return
|
||||
|
||||
text_to_translate = message.content
|
||||
import html
|
||||
text_escaped = html.escape(message.content)
|
||||
|
||||
mention_pattern = re.compile(r'<@!?(\d+)>|<@&(\d+)>|<#(\d+)>')
|
||||
# Buscamos menciones que ya están escapadas (<@...>)
|
||||
mention_pattern = re.compile(r'<@!?(\d+)>|<@&(\d+)>|<#(\d+)>')
|
||||
mentions_map = {}
|
||||
|
||||
def replace_mention(match):
|
||||
placeholder = f"__MENTION_{len(mentions_map)}__"
|
||||
mentions_map[placeholder] = match.group(0)
|
||||
# Usamos una etiqueta autocerrada para que el traductor no intente cerrarla él mismo
|
||||
placeholder = f"<m{len(mentions_map)} />"
|
||||
# Guardamos la mención original (sin escapar) para restaurarla luego
|
||||
mentions_map[placeholder] = html.unescape(match.group(0))
|
||||
return placeholder
|
||||
|
||||
text_to_translate = mention_pattern.sub(replace_mention, text_to_translate)
|
||||
text_to_translate = mention_pattern.sub(replace_mention, text_escaped)
|
||||
|
||||
langs_to_show = active_langs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user