Skip to content

Commit

Permalink
🐛 fix telegram file build
Browse files Browse the repository at this point in the history
resolve #79
  • Loading branch information
RF-Tar-Railt committed Nov 24, 2024
1 parent 2c46c4d commit bc5fbbb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
from .uniseg import SupportAdapterModule as SupportAdapterModule
from .extension import add_global_extension as add_global_extension

__version__ = "0.54.0"
__version__ = "0.54.1"

__plugin_meta__ = PluginMetadata(
name="Alconna 插件",
Expand Down
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/uniseg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from .constraint import SupportAdapterModule as SupportAdapterModule
from .adapters import alter_get_builder, alter_get_fetcher, alter_get_exporter

__version__ = "0.54.0"
__version__ = "0.54.1"

__plugin_meta__ = PluginMetadata(
name="Universal Segment 插件",
Expand Down
18 changes: 13 additions & 5 deletions src/nonebot_plugin_alconna/uniseg/adapters/telegram/builder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import TYPE_CHECKING

from nonebot.adapters import Bot, Event
from nonebot.adapters.telegram.message import Entity
from nonebot.adapters.telegram.event import MessageEvent
from nonebot.adapters.telegram.message import File as FileSegment
from nonebot.adapters.telegram.message import Entity, UnCombinFile
from nonebot.adapters.telegram.message import Reply as ReplySegment

from nonebot_plugin_alconna.uniseg.constraint import SupportAdapter
Expand Down Expand Up @@ -34,19 +34,27 @@ def photo(self, seg: FileSegment):

@build("video", "animation")
def video(self, seg: FileSegment):
return Video(id=seg.data["file_id"])
return Video(id=seg.data["file"])

@build("sticker")
def sticker(self, seg: UnCombinFile):
return Image(id=seg.data["file"])

@build("video_note")
def video_note(self, seg: UnCombinFile):
return Video(id=seg.data["file"])

@build("voice")
def voice(self, seg: FileSegment):
return Voice(id=seg.data["file_id"])
return Voice(id=seg.data["file"])

@build("audio")
def audio(self, seg: FileSegment):
return Audio(id=seg.data["file_id"])
return Audio(id=seg.data["file"])

@build("document")
def document(self, seg: FileSegment):
return File(seg.data["file_id"], name=seg.data["file_name"])
return File(seg.data["file"], name=seg.data.get("file_name", "file. bin"))

@build("reply")
def reply(self, seg: ReplySegment):
Expand Down
4 changes: 4 additions & 0 deletions src/nonebot_plugin_alconna/uniseg/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ async def reply_fetch(event: Event, bot: Bot):


async def image_fetch(event: Event, bot: Bot, state: T_State, img: Image, **kwargs) -> Optional[bytes]:
if img.raw:
return img.raw_bytes
if img.path:
return Path(img.path).read_bytes()
adapter_name = bot.adapter.get_name()
if adapter_name == "RedProtocol":
origin = img.origin
Expand Down

0 comments on commit bc5fbbb

Please sign in to comment.