diff --git a/nonebot_plugin_chatrecorder/adapters/__init__.py b/nonebot_plugin_chatrecorder/adapters/__init__.py index 7ed1009..f018685 100644 --- a/nonebot_plugin_chatrecorder/adapters/__init__.py +++ b/nonebot_plugin_chatrecorder/adapters/__init__.py @@ -7,5 +7,6 @@ from . import onebot_v12 as onebot_v12 from . import qqguild as qqguild from . import red as red +from . import satori as satori from . import telegram as telegram from . import villa as villa diff --git a/nonebot_plugin_chatrecorder/adapters/satori.py b/nonebot_plugin_chatrecorder/adapters/satori.py new file mode 100644 index 0000000..d1f14e1 --- /dev/null +++ b/nonebot_plugin_chatrecorder/adapters/satori.py @@ -0,0 +1,125 @@ +from datetime import datetime, timezone +from typing import Any, Dict, List, Optional, Type, cast + +from nonebot.adapters import Bot as BaseBot +from nonebot.message import event_postprocessor +from nonebot_plugin_orm import get_session +from nonebot_plugin_session import Session, SessionLevel, extract_session +from nonebot_plugin_session_orm import get_session_persist_id +from typing_extensions import override + +from ..config import plugin_config +from ..consts import SupportedAdapter +from ..message import ( + MessageDeserializer, + MessageSerializer, + register_deserializer, + register_serializer, + serialize_message, +) +from ..model import MessageRecord +from ..utils import remove_timezone + +try: + from nonebot.adapters.satori import Bot, Message, MessageEvent + from nonebot.adapters.satori.models import InnerMessage as SatoriMessage + + adapter = SupportedAdapter.satori + + @event_postprocessor + async def record_recv_msg(bot: Bot, event: MessageEvent): + session = extract_session(bot, event) + session_persist_id = await get_session_persist_id(session) + + record = MessageRecord( + session_persist_id=session_persist_id, + time=remove_timezone(event.timestamp.astimezone(timezone.utc)), + type=event.get_type(), + message_id=event.message.id, + message=serialize_message(adapter, event.get_message()), + plain_text=event.get_plaintext(), + ) + async with get_session() as db_session: + db_session.add(record) + await db_session.commit() + + if plugin_config.chatrecorder_record_send_msg: + + @Bot.on_called_api + async def record_send_msg( + bot: BaseBot, + e: Optional[Exception], + api: str, + data: Dict[str, Any], + result: Optional[Any], + ): + if not isinstance(bot, Bot): + return + if e or not result or not isinstance(result, list): + return + if api not in ["message_create"]: + return + for res in result: + if not isinstance(res, SatoriMessage): + return + result_messages = cast(List[SatoriMessage], result) + + result_message = result_messages[0] + level = SessionLevel.LEVEL0 + if result_message.guild: + level = SessionLevel.LEVEL3 + elif result_message.member: + level = SessionLevel.LEVEL2 + elif result_message.user: + level = SessionLevel.LEVEL1 + id1 = data["channel_id"] if level == SessionLevel.LEVEL1 else None + id2 = result_message.channel.id if result_message.channel else None + id3 = result_message.guild.id if result_message.guild else None + + session = Session( + bot_id=bot.self_id, + bot_type=bot.type, + platform=bot.platform, + level=level, + id1=id1, + id2=id2, + id3=id3, + ) + session_persist_id = await get_session_persist_id(session) + + message_id = "_".join([msg.id for msg in result_messages]) + message = Message() + for msg in result_messages: + message += Message.from_satori_element(msg.content) + message_time = ( + remove_timezone(result_message.created_at.astimezone(timezone.utc)) + if result_message.created_at + else datetime.utcnow() + ) + + record = MessageRecord( + session_persist_id=session_persist_id, + time=message_time, + type="message_sent", + message_id=message_id, + message=serialize_message(adapter, message), + plain_text=message.extract_plain_text(), + ) + async with get_session() as db_session: + db_session.add(record) + await db_session.commit() + + class Serializer(MessageSerializer[Message]): + pass + + class Deserializer(MessageDeserializer[Message]): + @classmethod + @override + def get_message_class(cls) -> Type[Message]: + return Message + + register_serializer(adapter, Serializer) + register_deserializer(adapter, Deserializer) + +except ImportError: + pass diff --git a/nonebot_plugin_chatrecorder/consts.py b/nonebot_plugin_chatrecorder/consts.py index c8890fd..61a847e 100644 --- a/nonebot_plugin_chatrecorder/consts.py +++ b/nonebot_plugin_chatrecorder/consts.py @@ -23,6 +23,7 @@ class SupportedAdapter(StrEnum): discord = "Discord" dodo = "DoDo" villa = "Villa" + satori = "Satori" class SupportedPlatform(StrEnum): diff --git a/poetry.lock b/poetry.lock index 0717d36..379a14f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,10 +1,9 @@ -# This file is automatically @generated by Poetry and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "aiomysql" version = "0.1.1" description = "MySQL driver for asyncio." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -23,7 +22,6 @@ sa = ["sqlalchemy (>=1.0,<1.4)"] name = "aiosqlite" version = "0.19.0" description = "asyncio bridge to the standard sqlite3 module" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -37,14 +35,13 @@ docs = ["sphinx (==6.1.3)", "sphinx-mdinclude (==0.5.3)"] [[package]] name = "alembic" -version = "1.12.1" +version = "1.13.0" description = "A database migration tool for SQLAlchemy." -category = "main" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "alembic-1.12.1-py3-none-any.whl", hash = "sha256:47d52e3dfb03666ed945becb723d6482e52190917fdb47071440cfdba05d92cb"}, - {file = "alembic-1.12.1.tar.gz", hash = "sha256:bca5877e9678b454706347bc10b97cb7d67f300320fa5c3a94423e8266e2823f"}, + {file = "alembic-1.13.0-py3-none-any.whl", hash = "sha256:a23974ea301c3ee52705db809c7413cecd165290c6679b9998dd6c74342ca23a"}, + {file = "alembic-1.13.0.tar.gz", hash = "sha256:ab4b3b94d2e1e5f81e34be8a9b7b7575fc9dd5398fccb0bef351ec9b14872623"}, ] [package.dependencies] @@ -55,13 +52,12 @@ SQLAlchemy = ">=1.3.0" typing-extensions = ">=4" [package.extras] -tz = ["python-dateutil"] +tz = ["backports.zoneinfo"] [[package]] name = "anyio" version = "3.7.1" description = "High level compatibility layer for multiple asynchronous event loop implementations" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -83,7 +79,6 @@ trio = ["trio (<0.22)"] name = "arrow" version = "1.3.0" description = "Better dates & times for Python" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -97,13 +92,12 @@ types-python-dateutil = ">=2.8.10" [package.extras] doc = ["doc8", "sphinx (>=7.0.0)", "sphinx-autobuild", "sphinx-autodoc-typehints", "sphinx_rtd_theme (>=1.3.0)"] -test = ["dateparser (>=1.0.0,<2.0.0)", "pre-commit", "pytest", "pytest-cov", "pytest-mock", "pytz (==2021.1)", "simplejson (>=3.0.0,<4.0.0)"] +test = ["dateparser (==1.*)", "pre-commit", "pytest", "pytest-cov", "pytest-mock", "pytz (==2021.1)", "simplejson (==3.*)"] [[package]] name = "asgiref" version = "3.7.2" description = "ASGI specs, helper code, and adapters" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -121,7 +115,6 @@ tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] name = "async-asgi-testclient" version = "1.4.11" description = "Async client for testing ASGI web applications" -category = "dev" optional = false python-versions = "*" files = [ @@ -136,7 +129,6 @@ requests = ">=2.21,<3.0" name = "asyncpg" version = "0.27.0" description = "An asyncio PostgreSQL driver" -category = "dev" optional = false python-versions = ">=3.7.0" files = [ @@ -187,7 +179,6 @@ test = ["flake8 (>=5.0.4,<5.1.0)", "uvloop (>=0.15.3)"] name = "betterproto" version = "1.2.5" description = "A better Protobuf / gRPC generator & library" -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -205,7 +196,6 @@ compiler = ["black", "jinja2", "protobuf"] name = "binaryornot" version = "0.4.4" description = "Ultra-lightweight pure Python package to check if a file is binary or text." -category = "dev" optional = false python-versions = "*" files = [ @@ -220,7 +210,6 @@ chardet = ">=3.0.2" name = "cashews" version = "6.3.0" description = "cache tools with async power" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -239,7 +228,6 @@ tests = ["hypothesis", "pytest", "pytest-asyncio"] name = "certifi" version = "2023.11.17" description = "Python package for providing Mozilla's CA Bundle." -category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -251,7 +239,6 @@ files = [ name = "chardet" version = "5.2.0" description = "Universal encoding detector for Python 3" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -263,7 +250,6 @@ files = [ name = "charset-normalizer" version = "3.3.2" description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." -category = "dev" optional = false python-versions = ">=3.7.0" files = [ @@ -363,7 +349,6 @@ files = [ name = "click" version = "8.1.7" description = "Composable command line interface toolkit" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -378,7 +363,6 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""} name = "colorama" version = "0.4.6" description = "Cross-platform colored terminal text." -category = "main" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" files = [ @@ -390,7 +374,6 @@ files = [ name = "cookiecutter" version = "2.5.0" description = "A command-line utility that creates projects from project templates, e.g. creating a Python package project from a Python package project template." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -412,7 +395,6 @@ rich = "*" name = "coverage" version = "7.3.2" description = "Code coverage measurement for Python" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -480,7 +462,6 @@ toml = ["tomli"] name = "distlib" version = "0.3.7" description = "Distribution utilities" -category = "dev" optional = false python-versions = "*" files = [ @@ -492,7 +473,6 @@ files = [ name = "exceptiongroup" version = "1.2.0" description = "Backport of PEP 654 (exception groups)" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -507,7 +487,6 @@ test = ["pytest (>=6)"] name = "execnet" version = "2.0.2" description = "execnet: rapid multi-Python deployment" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -522,7 +501,6 @@ testing = ["hatch", "pre-commit", "pytest", "tox"] name = "fastapi" version = "0.104.1" description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production" -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -543,7 +521,6 @@ all = ["email-validator (>=2.0.0)", "httpx (>=0.23.0)", "itsdangerous (>=1.1.0)" name = "filelock" version = "3.13.1" description = "A platform independent file lock." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -560,7 +537,6 @@ typing = ["typing-extensions (>=4.8)"] name = "greenlet" version = "3.0.1" description = "Lightweight in-process concurrent programming" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -631,7 +607,6 @@ test = ["objgraph", "psutil"] name = "grpclib" version = "0.4.6" description = "Pure-Python gRPC implementation for asyncio" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -649,7 +624,6 @@ protobuf = ["protobuf (>=3.20.0)"] name = "h11" version = "0.14.0" description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -661,7 +635,6 @@ files = [ name = "h2" version = "4.1.0" description = "HTTP/2 State-Machine based protocol implementation" -category = "dev" optional = false python-versions = ">=3.6.1" files = [ @@ -677,7 +650,6 @@ hyperframe = ">=6.0,<7" name = "hpack" version = "4.0.0" description = "Pure-Python HPACK header compression" -category = "dev" optional = false python-versions = ">=3.6.1" files = [ @@ -689,7 +661,6 @@ files = [ name = "httpcore" version = "1.0.2" description = "A minimal low-level HTTP client." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -704,14 +675,13 @@ h11 = ">=0.13,<0.15" [package.extras] asyncio = ["anyio (>=4.0,<5.0)"] http2 = ["h2 (>=3,<5)"] -socks = ["socksio (>=1.0.0,<2.0.0)"] +socks = ["socksio (==1.*)"] trio = ["trio (>=0.22.0,<0.23.0)"] [[package]] name = "httptools" version = "0.6.1" description = "A collection of framework independent HTTP protocol utils." -category = "main" optional = false python-versions = ">=3.8.0" files = [ @@ -760,7 +730,6 @@ test = ["Cython (>=0.29.24,<0.30.0)"] name = "httpx" version = "0.25.2" description = "The next generation HTTP client." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -772,21 +741,20 @@ files = [ anyio = "*" certifi = "*" h2 = {version = ">=3,<5", optional = true, markers = "extra == \"http2\""} -httpcore = ">=1.0.0,<2.0.0" +httpcore = "==1.*" idna = "*" sniffio = "*" [package.extras] brotli = ["brotli", "brotlicffi"] -cli = ["click (>=8.0.0,<9.0.0)", "pygments (>=2.0.0,<3.0.0)", "rich (>=10,<14)"] +cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"] http2 = ["h2 (>=3,<5)"] -socks = ["socksio (>=1.0.0,<2.0.0)"] +socks = ["socksio (==1.*)"] [[package]] name = "hyperframe" version = "6.0.1" description = "HTTP/2 framing layer for Python" -category = "dev" optional = false python-versions = ">=3.6.1" files = [ @@ -798,7 +766,6 @@ files = [ name = "idna" version = "3.6" description = "Internationalized Domain Names in Applications (IDNA)" -category = "main" optional = false python-versions = ">=3.5" files = [ @@ -808,21 +775,20 @@ files = [ [[package]] name = "importlib-metadata" -version = "6.8.0" +version = "6.11.0" description = "Read metadata from Python packages" -category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "importlib_metadata-6.8.0-py3-none-any.whl", hash = "sha256:3ebb78df84a805d7698245025b975d9d67053cd94c79245ba4b3eb694abe68bb"}, - {file = "importlib_metadata-6.8.0.tar.gz", hash = "sha256:dbace7892d8c0c4ac1ad096662232f831d4e64f4c4545bd53016a3e9d4654743"}, + {file = "importlib_metadata-6.11.0-py3-none-any.whl", hash = "sha256:f0afba6205ad8f8947c7d338b5342d5db2afbfd82f9cbef7879a9539cc12eb9b"}, + {file = "importlib_metadata-6.11.0.tar.gz", hash = "sha256:1231cf92d825c9e03cfc4da076a16de6422c863558229ea0b22b675657463443"}, ] [package.dependencies] zipp = ">=0.5" [package.extras] -docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-lint"] perf = ["ipython"] testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)", "pytest-ruff"] @@ -830,7 +796,6 @@ testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs name = "importlib-resources" version = "6.1.1" description = "Read resources from Python packages" -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -849,7 +814,6 @@ testing = ["pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", name = "iniconfig" version = "2.0.0" description = "brain-dead simple config-ini parsing" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -861,7 +825,6 @@ files = [ name = "jinja2" version = "3.1.2" description = "A very fast and expressive template engine." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -879,7 +842,6 @@ i18n = ["Babel (>=2.7)"] name = "linkify-it-py" version = "2.0.2" description = "Links recognition library with FULL unicode support." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -900,7 +862,6 @@ test = ["coverage", "pytest", "pytest-cov"] name = "loguru" version = "0.7.2" description = "Python logging made (stupidly) simple" -category = "main" optional = false python-versions = ">=3.5" files = [ @@ -919,7 +880,6 @@ dev = ["Sphinx (==7.2.5)", "colorama (==0.4.5)", "colorama (==0.4.6)", "exceptio name = "mako" version = "1.3.0" description = "A super-fast templating language that borrows the best ideas from the existing templating languages." -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -939,7 +899,6 @@ testing = ["pytest"] name = "markdown-it-py" version = "3.0.0" description = "Python port of markdown-it. Markdown parsing, done right!" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -966,7 +925,6 @@ testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"] name = "markupsafe" version = "2.1.3" description = "Safely add untrusted strings to HTML/XML markup." -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1036,7 +994,6 @@ files = [ name = "mdit-py-plugins" version = "0.4.0" description = "Collection of plugins for markdown-it-py" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -1056,7 +1013,6 @@ testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"] name = "mdurl" version = "0.1.2" description = "Markdown URL utilities" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1068,7 +1024,6 @@ files = [ name = "msgpack" version = "1.0.7" description = "MessagePack serializer" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -1134,7 +1089,6 @@ files = [ name = "multidict" version = "6.0.4" description = "multidict implementation" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1216,14 +1170,13 @@ files = [ [[package]] name = "nb-cli" -version = "1.2.6" +version = "1.2.7" description = "CLI for nonebot2" -category = "dev" optional = false python-versions = ">=3.8, <4.0" files = [ - {file = "nb-cli-1.2.6.tar.gz", hash = "sha256:33ca8ffdb721ea50751c47788789c84cd7594afc888ccfb2439f06ff95cbbd7c"}, - {file = "nb_cli-1.2.6-py3-none-any.whl", hash = "sha256:2aa52e0d21fb8a5a08662b691fa6cd521c99140aa0e24a81503264129f4b3045"}, + {file = "nb-cli-1.2.7.tar.gz", hash = "sha256:a868f03c2da9ccdfbdebd067f70c0f8e687ab904aebbea7f3a9a01853705e483"}, + {file = "nb_cli-1.2.7-py3-none-any.whl", hash = "sha256:574914fa224a25952a6ad60e7165b6208ebd8519d4f91b738f48210febf8b66c"}, ] [package.dependencies] @@ -1247,7 +1200,6 @@ wcwidth = ">=0.2,<1.0" name = "nonebot-adapter-console" version = "0.4.0" description = "console adapter for nonebot2" -category = "dev" optional = false python-versions = "<4.0,>=3.8" files = [ @@ -1263,7 +1215,6 @@ nonechat = ">=0.2.0,<1.0.0" name = "nonebot-adapter-discord" version = "0.1.1" description = "Discord adapter for nonebot2" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1276,14 +1227,13 @@ nonebot2 = ">=2.0.0,<3.0.0" [[package]] name = "nonebot-adapter-dodo" -version = "0.1.3" +version = "0.1.4" description = "Dodo adapter for nonebot2" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ - {file = "nonebot_adapter_dodo-0.1.3-py3-none-any.whl", hash = "sha256:9c8adb0eaafbd7b83a2290c20849ad8001b70df58fc7c9ecb76b43b3895e5bbf"}, - {file = "nonebot_adapter_dodo-0.1.3.tar.gz", hash = "sha256:20bbad55a01b1e968b0e26536e3a1c20a6bb56261e39dcde03e534f280a9289f"}, + {file = "nonebot_adapter_dodo-0.1.4-py3-none-any.whl", hash = "sha256:3bbe8ce1d686923dc7347d49e9e7164a93bc87e79626d6067e77b7c3d41d6861"}, + {file = "nonebot_adapter_dodo-0.1.4.tar.gz", hash = "sha256:21375ee712e97fe546ef24654dcb479f51e972335f13b4208af9ef53cc5fca29"}, ] [package.dependencies] @@ -1293,7 +1243,6 @@ nonebot2 = ">=2.0.0,<3.0.0" name = "nonebot-adapter-feishu" version = "2.3.1" description = "feishu(larksuite) adapter for nonebot2" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1310,7 +1259,6 @@ pycryptodome = ">=3.18.0,<4.0.0" name = "nonebot-adapter-kaiheila" version = "0.2.12" description = "kaiheila adapter for nonebot2" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1325,7 +1273,6 @@ nonebot2 = ">=2.0.0,<3.0.0" name = "nonebot-adapter-onebot" version = "2.3.1" description = "OneBot(CQHTTP) adapter for nonebot2" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1342,7 +1289,6 @@ typing-extensions = ">=4.0.0,<5.0.0" name = "nonebot-adapter-qqguild" version = "0.2.5" description = "QQ Guild adapter for nonebot2" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1356,14 +1302,13 @@ pydantic = ">=1.9.0,<2.0.0" [[package]] name = "nonebot-adapter-red" -version = "0.5.2" +version = "0.7.4" description = "Red Protocol Adapter for Nonebot2" -category = "dev" optional = false python-versions = ">=3.8" files = [ - {file = "nonebot_adapter_red-0.5.2-py3-none-any.whl", hash = "sha256:fb0743411836f2d3351575e3f75f78c80fb6c8c0fe1b71256369cc737fe595ad"}, - {file = "nonebot_adapter_red-0.5.2.tar.gz", hash = "sha256:11467b509ef75f7d920a0fe870287a9fea6fbe3a7ce6903eee287f63d893019d"}, + {file = "nonebot_adapter_red-0.7.4-py3-none-any.whl", hash = "sha256:f886c6615ba3333ea6391a03f3418f22043c7f94a69236d8b23dac8b8a2fea14"}, + {file = "nonebot_adapter_red-0.7.4.tar.gz", hash = "sha256:22253bcb8f4ec188d1d9293b1d42f4f87c6034dd4a607919961890d062d27c1f"}, ] [package.dependencies] @@ -1373,11 +1318,24 @@ packaging = ">=23.1" [package.extras] auto-detect = ["PyYAML"] +[[package]] +name = "nonebot-adapter-satori" +version = "0.8.0" +description = "Satori Protocol Adapter for Nonebot2" +optional = false +python-versions = ">=3.8" +files = [ + {file = "nonebot_adapter_satori-0.8.0-py3-none-any.whl", hash = "sha256:25d9726a961b73b6900a4dba3a8ec4f5d228a6cb96078b542379c9d6c9d3cefe"}, + {file = "nonebot_adapter_satori-0.8.0.tar.gz", hash = "sha256:267c5b708ec2dd77b405d3ec779e817506e6d6914cc06688b529b43fe4288727"}, +] + +[package.dependencies] +nonebot2 = ">=2.1.0" + [[package]] name = "nonebot-adapter-telegram" version = "0.1.0b14" description = "Telegram Adapter for NoneBot2" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1391,14 +1349,13 @@ nonebot2 = ">=2.0.0b1,<3.0.0" [[package]] name = "nonebot-adapter-villa" -version = "1.2.2" +version = "1.3.4" description = "NoneBot2 米游社大别野 Bot 适配器。MiHoYo Villa Bot adapter for nonebot2." -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ - {file = "nonebot_adapter_villa-1.2.2-py3-none-any.whl", hash = "sha256:993a89d978471dfa2a59030ac4ffd9fb043b0a8ee3576b4461dfbf1ae26a244f"}, - {file = "nonebot_adapter_villa-1.2.2.tar.gz", hash = "sha256:a10841c3ea02ea75152dfee4cd6cdc1b67c6ff0aa1f0b04a51f5b77ee68e206b"}, + {file = "nonebot_adapter_villa-1.3.4-py3-none-any.whl", hash = "sha256:bedd4bd1d6d80f26ca779b0df64a7e82c6654f3cbbdc97bfb4026509520274c3"}, + {file = "nonebot_adapter_villa-1.3.4.tar.gz", hash = "sha256:ab6740a9852c3827702728904cdb3eb1aafa58e6ce2a70900c26cf3bd23d5d81"}, ] [package.dependencies] @@ -1410,7 +1367,6 @@ rsa = ">=4.9,<5.0" name = "nonebot-plugin-datastore" version = "1.1.2" description = "适用于 Nonebot2 的数据存储插件" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1434,7 +1390,6 @@ yaml = ["pyyaml (>=6.0)"] name = "nonebot-plugin-localstore" version = "0.5.1" description = "Local Storage Support for NoneBot2" -category = "main" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1450,7 +1405,6 @@ typing-extensions = ">=4.0.0" name = "nonebot-plugin-orm" version = "0.6.0" description = "SQLAlchemy ORM support for nonebot" -category = "main" optional = false python-versions = "<4.0,>=3.8" files = [ @@ -1484,7 +1438,6 @@ sqlite = ["aiosqlite (>=0.19,<1.0)"] name = "nonebot-plugin-session" version = "0.2.3" description = "Nonebot2 会话信息提取与会话id定义" -category = "main" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1500,7 +1453,6 @@ strenum = ">=0.4.8,<0.5.0" name = "nonebot-plugin-session-orm" version = "0.1.1" description = "session 插件 orm 扩展" -category = "main" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1517,7 +1469,6 @@ nonebot2 = {version = ">=2.0.1,<3.0.0", extras = ["fastapi"]} name = "nonebot2" version = "2.1.2" description = "An asynchronous python bot framework." -category = "main" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1548,7 +1499,6 @@ websockets = ["websockets (>=10.0)"] name = "nonebug" version = "0.3.5" description = "nonebot2 test framework" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1567,7 +1517,6 @@ typing-extensions = ">=4.0.0,<5.0.0" name = "nonechat" version = "0.2.1" description = "Awesome chat console using Textual" -category = "dev" optional = false python-versions = "<4.0,>=3.8" files = [ @@ -1582,7 +1531,6 @@ textual = ">=0.29.0,<0.30.0" name = "noneprompt" version = "0.1.9" description = "Prompt toolkit for console interaction" -category = "dev" optional = false python-versions = ">=3.8,<4.0" files = [ @@ -1597,7 +1545,6 @@ prompt-toolkit = ">=3.0.19,<4.0.0" name = "packaging" version = "23.2" description = "Core utilities for Python packages" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1609,7 +1556,6 @@ files = [ name = "platformdirs" version = "4.0.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1625,7 +1571,6 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-co name = "pluggy" version = "1.3.0" description = "plugin and hook calling mechanisms for python" -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -1641,7 +1586,6 @@ testing = ["pytest", "pytest-benchmark"] name = "prompt-toolkit" version = "3.0.41" description = "Library for building powerful interactive command lines in Python" -category = "dev" optional = false python-versions = ">=3.7.0" files = [ @@ -1656,7 +1600,6 @@ wcwidth = "*" name = "pyasn1" version = "0.5.1" description = "Pure-Python implementation of ASN.1 types and DER/BER/CER codecs (X.208)" -category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7" files = [ @@ -1668,7 +1611,6 @@ files = [ name = "pycryptodome" version = "3.19.0" description = "Cryptographic library for Python" -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" files = [ @@ -1710,7 +1652,6 @@ files = [ name = "pydantic" version = "1.10.13" description = "Data validation and settings management using python type hints" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1764,7 +1705,6 @@ email = ["email-validator (>=1.0.3)"] name = "pyfiglet" version = "0.8.post1" description = "Pure-python FIGlet implementation" -category = "dev" optional = false python-versions = "*" files = [ @@ -1776,7 +1716,6 @@ files = [ name = "pygments" version = "2.17.2" description = "Pygments is a syntax highlighting package written in Python." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1792,7 +1731,6 @@ windows-terminal = ["colorama (>=0.4.6)"] name = "pygtrie" version = "2.5.0" description = "A pure Python trie data structure implementation." -category = "main" optional = false python-versions = "*" files = [ @@ -1804,7 +1742,6 @@ files = [ name = "pymysql" version = "1.1.0" description = "Pure Python MySQL Driver" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1820,7 +1757,6 @@ rsa = ["cryptography"] name = "pytest" version = "7.4.3" description = "pytest: simple powerful testing with Python" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1843,7 +1779,6 @@ testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "no name = "pytest-asyncio" version = "0.21.1" description = "Pytest support for asyncio" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1862,7 +1797,6 @@ testing = ["coverage (>=6.2)", "flaky (>=3.5.0)", "hypothesis (>=5.7.1)", "mypy name = "pytest-cov" version = "4.1.0" description = "Pytest plugin for measuring coverage." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1881,7 +1815,6 @@ testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtuale name = "pytest-xdist" version = "3.5.0" description = "pytest xdist plugin for distributed testing, most importantly across multiple CPUs" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1902,7 +1835,6 @@ testing = ["filelock"] name = "python-dateutil" version = "2.8.2" description = "Extensions to the standard Python datetime module" -category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" files = [ @@ -1917,7 +1849,6 @@ six = ">=1.5" name = "python-dotenv" version = "1.0.0" description = "Read key-value pairs from a .env file and set them as environment variables" -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -1932,7 +1863,6 @@ cli = ["click (>=5.0)"] name = "python-slugify" version = "8.0.1" description = "A Python slugify application that also handles Unicode" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1950,7 +1880,6 @@ unidecode = ["Unidecode (>=1.1.1)"] name = "pyyaml" version = "6.0.1" description = "YAML parser and emitter for Python" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -2010,7 +1939,6 @@ files = [ name = "requests" version = "2.31.0" description = "Python HTTP for Humans." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -2032,7 +1960,6 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] name = "rich" version = "13.7.0" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" -category = "dev" optional = false python-versions = ">=3.7.0" files = [ @@ -2052,7 +1979,6 @@ jupyter = ["ipywidgets (>=7.5.1,<9)"] name = "rsa" version = "4.9" description = "Pure-Python RSA implementation" -category = "dev" optional = false python-versions = ">=3.6,<4" files = [ @@ -2067,7 +1993,6 @@ pyasn1 = ">=0.1.3" name = "six" version = "1.16.0" description = "Python 2 and 3 compatibility utilities" -category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" files = [ @@ -2079,7 +2004,6 @@ files = [ name = "sniffio" version = "1.3.0" description = "Sniff out which async library your code is running under" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -2091,7 +2015,6 @@ files = [ name = "sqlalchemy" version = "2.0.23" description = "Database Abstraction Library" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -2148,11 +2071,8 @@ files = [ [package.dependencies] aiosqlite = {version = "*", optional = true, markers = "extra == \"aiosqlite\""} -greenlet = {version = "!=0.4.17", markers = "platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\""} -typing-extensions = [ - {version = ">=4.2.0"}, - {version = "!=3.10.0.1", optional = true, markers = "extra == \"aiosqlite\""}, -] +greenlet = {version = "!=0.4.17", optional = true, markers = "platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\" or extra == \"aiosqlite\""} +typing-extensions = {version = ">=4.2.0", optional = true, markers = "extra == \"aiosqlite\""} [package.extras] aiomysql = ["aiomysql (>=0.2.0)", "greenlet (!=0.4.17)"] @@ -2183,7 +2103,6 @@ sqlcipher = ["sqlcipher3-binary"] name = "starlette" version = "0.27.0" description = "The little ASGI library that shines." -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -2202,7 +2121,6 @@ full = ["httpx (>=0.22.0)", "itsdangerous", "jinja2", "python-multipart", "pyyam name = "strenum" version = "0.4.15" description = "An Enum that inherits from str." -category = "main" optional = false python-versions = "*" files = [ @@ -2219,7 +2137,6 @@ test = ["pylint", "pytest", "pytest-black", "pytest-cov", "pytest-pylint"] name = "stringcase" version = "1.2.0" description = "String case converter." -category = "dev" optional = false python-versions = "*" files = [ @@ -2230,7 +2147,6 @@ files = [ name = "text-unidecode" version = "1.3" description = "The most basic Text::Unidecode port" -category = "dev" optional = false python-versions = "*" files = [ @@ -2242,7 +2158,6 @@ files = [ name = "textual" version = "0.29.0" description = "Modern Text User Interface framework" -category = "dev" optional = false python-versions = ">=3.7,<4.0" files = [ @@ -2260,7 +2175,6 @@ typing-extensions = ">=4.4.0,<5.0.0" name = "tomli" version = "2.0.1" description = "A lil' TOML parser" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -2272,7 +2186,6 @@ files = [ name = "tomlkit" version = "0.12.3" description = "Style preserving TOML library" -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -2284,7 +2197,6 @@ files = [ name = "types-python-dateutil" version = "2.8.19.14" description = "Typing stubs for python-dateutil" -category = "dev" optional = false python-versions = "*" files = [ @@ -2296,7 +2208,6 @@ files = [ name = "typing-extensions" version = "4.8.0" description = "Backported and Experimental Type Hints for Python 3.8+" -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -2308,7 +2219,6 @@ files = [ name = "uc-micro-py" version = "1.0.2" description = "Micro subset of unicode data files for linkify-it-py projects." -category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -2323,7 +2233,6 @@ test = ["coverage", "pytest", "pytest-cov"] name = "urllib3" version = "2.1.0" description = "HTTP library with thread-safe connection pooling, file post, and more." -category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -2340,7 +2249,6 @@ zstd = ["zstandard (>=0.18.0)"] name = "uvicorn" version = "0.24.0.post1" description = "The lightning-fast ASGI server." -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -2356,7 +2264,7 @@ httptools = {version = ">=0.5.0", optional = true, markers = "extra == \"standar python-dotenv = {version = ">=0.13", optional = true, markers = "extra == \"standard\""} pyyaml = {version = ">=5.1", optional = true, markers = "extra == \"standard\""} typing-extensions = {version = ">=4.0", markers = "python_version < \"3.11\""} -uvloop = {version = ">=0.14.0,<0.15.0 || >0.15.0,<0.15.1 || >0.15.1", optional = true, markers = "sys_platform != \"win32\" and sys_platform != \"cygwin\" and platform_python_implementation != \"PyPy\" and extra == \"standard\""} +uvloop = {version = ">=0.14.0,<0.15.0 || >0.15.0,<0.15.1 || >0.15.1", optional = true, markers = "(sys_platform != \"win32\" and sys_platform != \"cygwin\") and platform_python_implementation != \"PyPy\" and extra == \"standard\""} watchfiles = {version = ">=0.13", optional = true, markers = "extra == \"standard\""} websockets = {version = ">=10.4", optional = true, markers = "extra == \"standard\""} @@ -2367,7 +2275,6 @@ standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", name = "uvloop" version = "0.19.0" description = "Fast implementation of asyncio event loop on top of libuv" -category = "main" optional = false python-versions = ">=3.8.0" files = [ @@ -2410,14 +2317,13 @@ test = ["Cython (>=0.29.36,<0.30.0)", "aiohttp (==3.9.0b0)", "aiohttp (>=3.8.1)" [[package]] name = "virtualenv" -version = "20.24.7" +version = "20.25.0" description = "Virtual Python Environment builder" -category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "virtualenv-20.24.7-py3-none-any.whl", hash = "sha256:a18b3fd0314ca59a2e9f4b556819ed07183b3e9a3702ecfe213f593d44f7b3fd"}, - {file = "virtualenv-20.24.7.tar.gz", hash = "sha256:69050ffb42419c91f6c1284a7b24e0475d793447e35929b488bf6a0aade39353"}, + {file = "virtualenv-20.25.0-py3-none-any.whl", hash = "sha256:4238949c5ffe6876362d9c0180fc6c3a824a7b12b80604eeb8085f2ed7460de3"}, + {file = "virtualenv-20.25.0.tar.gz", hash = "sha256:bf51c0d9c7dd63ea8e44086fa1e4fb1093a31e963b86959257378aef020e1f1b"}, ] [package.dependencies] @@ -2433,7 +2339,6 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess name = "watchfiles" version = "0.21.0" description = "Simple, modern and high performance file watching and code reload in python." -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -2521,7 +2426,6 @@ anyio = ">=3.0.0" name = "wcwidth" version = "0.2.12" description = "Measures the displayed width of unicode strings in a terminal" -category = "dev" optional = false python-versions = "*" files = [ @@ -2533,7 +2437,6 @@ files = [ name = "websockets" version = "12.0" description = "An implementation of the WebSocket Protocol (RFC 6455 & 7692)" -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -2615,7 +2518,6 @@ files = [ name = "win32-setctime" version = "1.1.0" description = "A small Python utility to set file creation time on Windows" -category = "main" optional = false python-versions = ">=3.5" files = [ @@ -2630,7 +2532,6 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"] name = "yarl" version = "1.9.3" description = "Yet another URL library" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -2734,7 +2635,6 @@ multidict = ">=4.0" name = "zipp" version = "3.17.0" description = "Backport of pathlib-compatible object wrapper for zip files" -category = "main" optional = false python-versions = ">=3.8" files = [ @@ -2749,4 +2649,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "3e144aa85948935bdfb6e9b9af83b01ca71af5d8885d2b67bd2bc9f90e3efcb2" +content-hash = "31c279b033f7f128ed4e1193ce9ad8f90dbc82a089c8a0ec5e21d30d3b7e207a" diff --git a/pyproject.toml b/pyproject.toml index 0ac5e4b..44f141f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ repository = "https://github.com/noneplugin/nonebot-plugin-chatrecorder" [tool.poetry.dependencies] python = "^3.8" nonebot2 = { version = "^2.0.1", extras = ["fastapi"] } -nonebot-plugin-session = "^0.2.0" +nonebot-plugin-session = "^0.2.3" nonebot-plugin-orm = ">=0.3.0,<1.0.0" nonebot-plugin-session-orm = "^0.1.1" nonebot-plugin-localstore = "^0.5.0" @@ -39,10 +39,11 @@ nonebot-adapter-qqguild = "^0.2.5" nonebot-adapter-kaiheila = "^0.2.12" nonebot-adapter-telegram = "^0.1.0b14" nonebot-adapter-feishu = "^2.2.0" -nonebot-adapter-red = "^0.5.2" +nonebot-adapter-red = "^0.7.4" nonebot-adapter-discord = "^0.1.0b4" nonebot-adapter-dodo = "^0.1.3" nonebot-adapter-villa = "^1.2.2" +nonebot-adapter-satori = "^0.8.0" [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/tests/test_satori.py b/tests/test_satori.py new file mode 100644 index 0000000..d9b9cf6 --- /dev/null +++ b/tests/test_satori.py @@ -0,0 +1,198 @@ +from datetime import datetime + +from nonebot import get_driver +from nonebot.adapters.satori import Adapter, Bot, Message +from nonebot.adapters.satori.config import ClientInfo +from nonebot.adapters.satori.event import PublicMessageCreatedEvent +from nonebot.adapters.satori.models import Channel, ChannelType, Guild +from nonebot.adapters.satori.models import InnerMember as Member +from nonebot.adapters.satori.models import InnerMessage as SatoriMessage +from nonebot.adapters.satori.models import User +from nonebot.adapters.satori.utils import Element +from nonebug.app import App + +from .utils import check_record + + +async def test_record_recv_msg(app: App): + """测试记录收到的消息""" + from nonebot_plugin_chatrecorder.adapters.satori import record_recv_msg + from nonebot_plugin_chatrecorder.message import serialize_message + + async with app.test_api() as ctx: + bot = ctx.create_bot( + base=Bot, + adapter=Adapter(get_driver()), + self_id="2233", + platform="kook", + info=ClientInfo(port=5140), + ) + assert isinstance(bot, Bot) + + event = PublicMessageCreatedEvent.parse_obj( + { + "id": 4, + "type": "message-created", + "platform": "kook", + "self_id": "2233", + "timestamp": 17000000000, + "argv": None, + "button": None, + "channel": { + "id": "6677", + "type": 0, + "name": "文字频道", + "parent_id": None, + }, + "guild": {"id": "5566", "name": None, "avatar": None}, + "login": None, + "member": { + "user": None, + "name": None, + "nick": "Aislinn", + "avatar": None, + "joined_at": None, + }, + "message": { + "id": "56163f81-de30-4c39-b4c4-3a205d0be9da", + "content": [ + { + "type": "text", + "attrs": {"text": "test"}, + "children": [], + "source": None, + } + ], + "channel": None, + "guild": None, + "member": { + "user": { + "id": "3344", + "name": "Aislinn", + "nick": None, + "avatar": "https://img.kookapp.cn/avatars/2021-08/GjdUSjtmtD06j06j.png?x-oss-process=style/icon", + "is_bot": None, + "username": "Aislinn", + "user_id": "3344", + "discriminator": "4261", + }, + "name": None, + "nick": "Aislinn", + "avatar": None, + "joined_at": None, + }, + "user": { + "id": "3344", + "name": "Aislinn", + "nick": None, + "avatar": "https://img.kookapp.cn/avatars/2021-08/GjdUSjtmtD06j06j.png?x-oss-process=style/icon", + "is_bot": None, + "username": "Aislinn", + "user_id": "3344", + "discriminator": "4261", + }, + "created_at": None, + "updated_at": None, + "message_id": "56163f81-de30-4c39-b4c4-3a205d0be9da", + "elements": [ + {"type": "text", "attrs": {"content": "test"}, "children": []} + ], + "timestamp": 1700474858446, + }, + "operator": None, + "role": None, + "user": { + "id": "3344", + "name": "Aislinn", + "nick": None, + "avatar": "https://img.kookapp.cn/avatars/2021-08/GjdUSjtmtD06j06j.png?x-oss-process=style/icon", + "is_bot": None, + "username": "Aislinn", + "user_id": "3344", + "discriminator": "4261", + }, + "_type": "kook", + } + ) + await record_recv_msg(bot, event) + await check_record( + "2233", + "Satori", + "kook", + 3, + "3344", + "6677", + "5566", + datetime.utcfromtimestamp(17000000000 / 1000), + "message", + "56163f81-de30-4c39-b4c4-3a205d0be9da", + serialize_message(bot, Message("test")), + "test", + ) + + +async def test_record_send_msg(app: App): + """测试记录发送的消息""" + from nonebot_plugin_chatrecorder.adapters.satori import record_send_msg + from nonebot_plugin_chatrecorder.message import serialize_message + + async with app.test_api() as ctx: + bot = ctx.create_bot( + base=Bot, + adapter=Adapter(get_driver()), + self_id="2233", + platform="kook", + info=ClientInfo(port=5140), + ) + assert isinstance(bot, Bot) + + await record_send_msg( + bot, + None, + "message_create", + {"channel_id": "6677", "content": "test"}, + [ + SatoriMessage( + id="6b701984-c185-4da9-9808-549dc9947b85", + content=[ + Element( + type="text", attrs={"text": "test"}, children=[], source=None + ) + ], + channel=Channel( + id="6677", type=ChannelType.TEXT, name="文字频道", parent_id=None + ), + guild=Guild(id="5566", name=None, avatar=None), + member=Member( + user=None, + name=None, + nick="Aislinn", + avatar=None, + joined_at=None, + ), + user=User( + id="3344", + name="Aislinn", + nick=None, + avatar="https://img.kookapp.cn/avatars/2021-08/GjdUSjtmtD06j06j.png?x-oss-process=style/icon", + is_bot=None, + ), + created_at=None, + updated_at=None, + ) + ], + ) + await check_record( + "2233", + "Satori", + "kook", + 3, + None, + "6677", + "5566", + None, + "message_sent", + "6b701984-c185-4da9-9808-549dc9947b85", + serialize_message(bot, Message("test")), + "test", + )