Skip to content

Commit

Permalink
🐛 support satori 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
shoucandanghehe committed Jun 14, 2024
1 parent ff4816a commit 500a29c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/nonebot_plugin_alconna/uniseg/adapters/satori/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ def get_satori_version():


class Loader(BaseLoader):

def __init__(self):
if version := get_satori_version():
if tuple(map(int, version.split(".")[:2])) < (0, 11):
raise ImportError("nonebot-adapter-satori>=0.11 is required.")
if tuple(map(int, version.split(".")[:2])) < (0, 12):
raise ImportError("nonebot-adapter-satori>=0.12 is required.")

def get_adapter(self) -> SupportAdapter:
return SupportAdapter.satori
Expand Down
8 changes: 4 additions & 4 deletions src/nonebot_plugin_alconna/uniseg/adapters/satori/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from nonebot.adapters.satori.message import STYLE_TYPE_MAP
from nonebot.adapters.satori.event import NoticeEvent, MessageEvent
from nonebot.adapters.satori.message import Message, MessageSegment
from nonebot.adapters.satori.models import ChannelType, InnerMessage
from nonebot.adapters.satori.models import ChannelType, MessageObject

from nonebot_plugin_alconna.uniseg.target import Target
from nonebot_plugin_alconna.uniseg.constraint import SupportScope
Expand Down Expand Up @@ -171,7 +171,7 @@ async def send_to(self, target: Union[Target, Event], bot: Bot, message: Message

async def recall(self, mid: Any, bot: Bot, context: Union[Target, Event]):
assert isinstance(bot, SatoriBot)
_mid: InnerMessage = cast(InnerMessage, mid)
_mid: MessageObject = cast(MessageObject, mid)
if isinstance(context, Target):
if context.private:
channel = await bot.user_channel_create(user_id=context.id)
Expand All @@ -190,7 +190,7 @@ async def edit(self, new: Message, mid: Any, bot: Bot, context: Union[Target, Ev
if TYPE_CHECKING:
assert isinstance(new, self.get_message_type())

_mid: InnerMessage = cast(InnerMessage, mid)
_mid: MessageObject = cast(MessageObject, mid)
if isinstance(context, Target):
if context.private:
channel = await bot.user_channel_create(user_id=context.id)
Expand All @@ -202,5 +202,5 @@ async def edit(self, new: Message, mid: Any, bot: Bot, context: Union[Target, Ev
return await bot.update_message(channel.id, _mid.id, new)

def get_reply(self, mid: Any):
_mid: InnerMessage = cast(InnerMessage, mid)
_mid: MessageObject = cast(MessageObject, mid)
return Reply(_mid.id)
4 changes: 2 additions & 2 deletions tests/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def fake_message_event_satori(**field) -> "SatoriMessageEvent":
from pydantic import create_model
from nonebot.adapters.satori import Message
from nonebot.adapters.satori.event import MessageEvent
from nonebot.adapters.satori.models import User, Channel, ChannelType, InnerMessage
from nonebot.adapters.satori.models import User, Channel, ChannelType, MessageObject

_Fake = create_model("_Fake", __base__=MessageEvent)

Expand All @@ -101,7 +101,7 @@ class FakeEvent(_Fake):
timestamp: datetime = datetime.fromtimestamp(1000000)
channel: Channel = Channel(id="1", type=ChannelType.TEXT)
user: User = User(id="1", name="test")
message: InnerMessage = InnerMessage(id="1", content="text")
message: MessageObject = MessageObject(id="1", content="text")
to_me: bool = False

class Config:
Expand Down

0 comments on commit 500a29c

Please sign in to comment.