fix(telegram): 修复 disable_web_page_preview 传递给不支持的方法及 UTF-16 偏移量问题

1. disable_web_page_preview 仅在 send_message 时传入,避免 send_photo/send_document 抛出 TypeError
2. _embed_entity_links 中将 Telegram UTF-16 编码单位偏移量转换为 Python 字符偏移量,修复含 emoji 等非 BMP 字符时切片错误

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
DDSRem
2026-04-01 23:13:33 +08:00
committed by jxxghp
parent 5440dbae51
commit d9eb3295b0
2 changed files with 22 additions and 10 deletions

View File

@@ -294,12 +294,16 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
key=lambda e: e.get("offset", 0),
reverse=True,
)
text_utf16 = text.encode("utf-16-le")
for entity in text_link_entities:
offset = entity.get("offset", 0)
length = entity.get("length", 0)
url = entity["url"]
display_text = text[offset: offset + length]
text = text[:offset] + f"{display_text}({url})" + text[offset + length:]
char_offset = len(text_utf16[:offset * 2].decode("utf-16-le"))
char_length = len(text_utf16[offset * 2: (offset + length) * 2].decode("utf-16-le"))
display_text = text[char_offset: char_offset + char_length]
text = text[:char_offset] + f"{display_text}({url})" + text[char_offset + char_length:]
text_utf16 = text.encode("utf-16-le")
return text
@staticmethod