From 89273894706897ae6fb856f6dac2effa2d80019f Mon Sep 17 00:00:00 2001 From: student_2333 Date: Mon, 24 Jun 2024 17:16:26 +0800 Subject: [PATCH] feat: support `Media.name` in `telegram` adapter --- .../uniseg/adapters/telegram/exporter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nonebot_plugin_alconna/uniseg/adapters/telegram/exporter.py b/src/nonebot_plugin_alconna/uniseg/adapters/telegram/exporter.py index 8ea9c94..8c0a43f 100644 --- a/src/nonebot_plugin_alconna/uniseg/adapters/telegram/exporter.py +++ b/src/nonebot_plugin_alconna/uniseg/adapters/telegram/exporter.py @@ -98,12 +98,13 @@ async def media(self, seg: Union[Image, Voice, Video, Audio, File], bot: Bot) -> }[name] if seg.id or seg.url: return method(seg.id or seg.url) - elif seg.path: - return method(Path(seg.path).read_bytes()) + if seg.path: + raw = Path(seg.path).read_bytes() elif seg.raw: - return method(seg.raw_bytes) + raw = seg.raw_bytes else: raise SerializeFailed(lang.require("nbp-uniseg", "invalid_segment").format(type=name, seg=seg)) + return method((seg.name, raw) if seg.name else raw) @export async def reply(self, seg: Reply, bot: Bot) -> "MessageSegment":