From 3e7c47e873b905a6231e7b180f2f5eac26f50324 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 25 Feb 2025 01:32:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=9C=A8=20Telegram=20?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=99=A8=E4=B8=AD=E6=94=AF=E6=8C=81@?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=A2=9E=E5=BC=BA=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/platform/sources/telegram/tg_adapter.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index 0a931fa63..bbb4d6cf5 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -4,7 +4,7 @@ import asyncio from astrbot.api.platform import Platform, AstrBotMessage, MessageMember, PlatformMetadata, MessageType from astrbot.api.event import MessageChain -from astrbot.api.message_components import Plain, Image, Record, File as AstrBotFile, Video +from astrbot.api.message_components import Plain, Image, Record, File as AstrBotFile, Video, At from astrbot.core.platform.astr_message_event import MessageSesion from astrbot.api.platform import register_platform_adapter @@ -81,10 +81,21 @@ class TelegramPlatformAdapter(Platform): message.message_str = "" message.message = [] + logger.debug(f"Telegram message: {update.message}") + if update.message.text: plain_text = update.message.text - message.message = [Plain(plain_text),] + + if update.message.entities: + for entity in update.message.entities: + if entity.type == "mention": + name = plain_text[entity.offset:entity.offset+entity.length] + message.message.append(At(qq=message.self_id, name=name)) + plain_text = plain_text[:entity.offset] + plain_text[entity.offset+entity.length:] + + message.message.append(Plain(plain_text)) message.message_str = plain_text + elif update.message.voice: file = await update.message.voice.get_file()