From 87790e225d2b0538cbed8e2a619c58307bb48e3a Mon Sep 17 00:00:00 2001 From: Azide Date: Tue, 30 Jul 2024 15:38:18 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=94=AF=E6=8C=81=E6=96=B0?= =?UTF-8?q?=E7=89=88=E6=9C=ACadapter-satori?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_saa/adapters/satori.py | 18 ++++++++--------- poetry.lock | 12 +++++------ pyproject.toml | 2 +- tests/test_satori.py | 29 ++++++++++++++------------- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/nonebot_plugin_saa/adapters/satori.py b/nonebot_plugin_saa/adapters/satori.py index 95362d0..8d6070f 100644 --- a/nonebot_plugin_saa/adapters/satori.py +++ b/nonebot_plugin_saa/adapters/satori.py @@ -50,7 +50,7 @@ class SatoriPlatform(str, Enum): from nonebot.adapters.satori import Bot as BotSatori from nonebot.adapters.satori.models import PageResult from nonebot.adapters.satori import Message, MessageSegment - from nonebot.adapters.satori.models import InnerMessage as SatoriMessage + from nonebot.adapters.satori.models import MessageObject as SatoriMessage from nonebot.adapters.satori.event import ( MessageEvent, PublicMessageEvent, @@ -146,27 +146,27 @@ def _extract_group_msg_event(event: Event) -> PlatformTarget: @register_convert_to_arg(adapter, SupportedPlatform.qq_private) def _gen_qq_private(target: PlatformTarget) -> dict[str, Any]: assert isinstance(target, TargetQQPrivate) - return {"channel_id": f"private:{target.user_id}"} + return {"channel": f"private:{target.user_id}"} @register_convert_to_arg(adapter, SupportedPlatform.qq_group) def _gen_qq_group(target: PlatformTarget) -> dict[str, Any]: assert isinstance(target, TargetQQGroup) - return {"channel_id": str(target.group_id)} + return {"channel": str(target.group_id)} @register_convert_to_arg(adapter, SupportedPlatform.feishu_private) def _gen_feishu_private(target: PlatformTarget) -> dict[str, Any]: assert isinstance(target, TargetFeishuPrivate) - return {"channel_id": target.open_id} + return {"channel": target.open_id} @register_convert_to_arg(adapter, SupportedPlatform.feishu_group) def _gen_feishu_group(target: PlatformTarget) -> dict[str, Any]: assert isinstance(target, TargetFeishuGroup) - return {"channel_id": target.chat_id} + return {"channel": target.chat_id} @register_convert_to_arg(adapter, SupportedPlatform.telegram_common) def _gen_telegram_common(target: PlatformTarget) -> dict[str, Any]: assert isinstance(target, TargetTelegramCommon) - return {"channel_id": target.chat_id} + return {"channel": target.chat_id} @register_convert_to_arg(adapter, SupportedPlatform.unknown_satori) def _to_unknow(target: PlatformTarget): @@ -174,7 +174,7 @@ def _to_unknow(target: PlatformTarget): # TODO: 如果是私聊,需要先创建私聊会话 if target.channel_id is None: raise NotImplementedError - return {"channel_id": target.channel_id} + return {"channel": target.channel_id} class SatoriReceipt(Receipt): adapter_name: Literal[adapter] = adapter @@ -228,7 +228,7 @@ async def send( if event: resp = await bot.send_message( - message=message_to_send, channel_id=event.channel.id + message=message_to_send, channel=event.channel ) else: resp = await bot.send_message( @@ -258,7 +258,7 @@ async def aggregate_send( if event: assert isinstance(event, MessageEvent) - await bot.send_message(message=message_to_send, channel_id=event.channel.id) + await bot.send_message(message=message_to_send, channel=event.channel) else: await bot.send_message(message=message_to_send, **target.arg_dict(bot)) diff --git a/poetry.lock b/poetry.lock index 3fedf18..ddd3824 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1098,17 +1098,17 @@ auto-detect = ["PyYAML"] [[package]] name = "nonebot-adapter-satori" -version = "0.10.5" +version = "0.12.3" description = "Satori Protocol Adapter for Nonebot2" optional = false -python-versions = ">=3.8" +python-versions = ">=3.9" files = [ - {file = "nonebot_adapter_satori-0.10.5-py3-none-any.whl", hash = "sha256:3646a79634ef3e6c01d133b41b7c2511f330500e5ca91db35c0fc769a08e9486"}, - {file = "nonebot_adapter_satori-0.10.5.tar.gz", hash = "sha256:3acfd2790b7fde2f9495ffb09c057207c709e5130566b8cb8724461c58b587ed"}, + {file = "nonebot_adapter_satori-0.12.3-py3-none-any.whl", hash = "sha256:94670f6a558cee185b42470dbd928d747c3ba72bea4f98f391ab2c41e3b79e27"}, + {file = "nonebot_adapter_satori-0.12.3.tar.gz", hash = "sha256:5c2bd09fde92b36d863ba7cd85d5ca0fe8680ec2489d657f7ad8b0958cb9d9d8"}, ] [package.dependencies] -nonebot2 = ">=2.2.0" +nonebot2 = ">=2.3.0" [[package]] name = "nonebot-adapter-telegram" @@ -2371,4 +2371,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.9, <4.0" -content-hash = "ae79edad9a45d287f75e06dc56ae16e4518f3868366337a7352113cf0304bfba" +content-hash = "6291afdc0da354e7f7bda48c17e775220de94089d21a62502057374e684e539d" diff --git a/pyproject.toml b/pyproject.toml index f8fcf42..da3ca0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ nonebot-adapter-feishu = "^2.4.0" nonebot-adapter-red = "^0.9.0" nonebot-adapter-dodo = "^0.2.0" nonebot-adapter-qq = "^1.4.1" -nonebot-adapter-satori = "^0.10.2" +nonebot-adapter-satori = "^0.12.3" nonebot-adapter-discord = "^0.1.7" [tool.black] diff --git a/tests/test_satori.py b/tests/test_satori.py index 0d4c73b..b2f830e 100644 --- a/tests/test_satori.py +++ b/tests/test_satori.py @@ -11,11 +11,12 @@ from nonebot.compat import type_validate_python from nonebot.adapters.satori import Bot, Adapter from nonebot.adapters.satori.config import ClientInfo +from nonebot.adapters.satori.models import Login, LoginStatus from .utils import assert_ms, mock_satori_message_event -satori_kwargs: dict[Literal["platform", "info"], Any] = { - "platform": "qq", +satori_kwargs: dict[Literal["login", "info"], Any] = { + "login": Login(status=LoginStatus.ONLINE, platform="qq"), "info": ClientInfo(port=12345), } @@ -104,7 +105,7 @@ async def test_reply(app: App, assert_satori): async def test_send(app: App): from nonebot import get_driver, on_message from nonebot.adapters.satori import Bot, MessageEvent - from nonebot.adapters.satori.models import InnerMessage + from nonebot.adapters.satori.models import MessageObject from nonebot_plugin_saa import Text, MessageFactory, SupportedAdapters @@ -125,14 +126,14 @@ async def process(msg: MessageEvent): "channel_id": "67890", "content": "123", }, - [InnerMessage(id="321", content="321").model_dump()], + [MessageObject(id="321", content="321").model_dump()], ) async def test_extract_message_id(app: App): from nonebot import get_driver, on_message from nonebot.adapters.satori import Bot, MessageEvent - from nonebot.adapters.satori.models import InnerMessage + from nonebot.adapters.satori.models import MessageObject from nonebot_plugin_saa import Text, MessageFactory, SupportedAdapters from nonebot_plugin_saa.adapters.satori import SatoriReceipt, SatoriMessageId @@ -156,14 +157,14 @@ async def process(msg: MessageEvent): "channel_id": "67890", "content": "123", }, - [InnerMessage(id="321", content="321").model_dump()], + [MessageObject(id="321", content="321").model_dump()], ) async def test_send_with_reply_and_revoke(app: App): from nonebot import get_driver, on_message from nonebot.adapters.satori import Bot, MessageEvent - from nonebot.adapters.satori.models import Channel, ChannelType, InnerMessage + from nonebot.adapters.satori.models import Channel, ChannelType, MessageObject from nonebot_plugin_saa import Text, MessageFactory, SupportedAdapters @@ -186,7 +187,7 @@ async def process(msg: MessageEvent): "content": "123", }, [ - InnerMessage( + MessageObject( id="321", content="321", channel=Channel(id="67890", type=ChannelType.TEXT), @@ -202,7 +203,7 @@ async def process(msg: MessageEvent): async def test_send_active(app: App): from nonebot import get_driver, on_message from nonebot.adapters.satori import Bot, MessageEvent - from nonebot.adapters.satori.models import InnerMessage + from nonebot.adapters.satori.models import MessageObject from nonebot_plugin_saa import ( Text, @@ -234,7 +235,7 @@ async def process(msg: MessageEvent): "channel_id": "12345", "content": "123", }, - [InnerMessage(id="321", content="321").model_dump()], + [MessageObject(id="321", content="321").model_dump()], ) await MessageFactory(Text("123")).send_to(send_target_qq_group, bot) @@ -244,7 +245,7 @@ async def process(msg: MessageEvent): "channel_id": "private:12345", "content": "123", }, - [InnerMessage(id="321", content="321").model_dump()], + [MessageObject(id="321", content="321").model_dump()], ) await MessageFactory(Text("123")).send_to(send_target_qq_private, bot) @@ -254,7 +255,7 @@ async def process(msg: MessageEvent): "channel_id": "67890", "content": "123", }, - [InnerMessage(id="321", content="321").model_dump()], + [MessageObject(id="321", content="321").model_dump()], ) await MessageFactory(Text("123")).send_to(send_target_satori_unknown, bot) @@ -262,7 +263,7 @@ async def process(msg: MessageEvent): async def test_send_aggreted_satori(app: App): from nonebot import get_driver, on_message from nonebot.adapters.satori import Bot, MessageEvent - from nonebot.adapters.satori.models import InnerMessage + from nonebot.adapters.satori.models import MessageObject from nonebot_plugin_saa import Text, SupportedAdapters, AggregatedMessageFactory @@ -282,7 +283,7 @@ async def process(msg: MessageEvent): "channel_id": "67890", "content": "123456", }, - [InnerMessage(id="321", content="321").model_dump()], + [MessageObject(id="321", content="321").model_dump()], ) ctx.receive_event(bot, msg_event)