From e3a878673f080818bffc0b45026a20c95921448f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wuyi=E6=97=A0=E7=96=91?= <444835641@qq.com> Date: Mon, 3 Apr 2023 23:32:50 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E9=80=82=E9=85=8D`onebotv11`?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E6=B6=88=E6=81=AF=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=20(#480)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GenshinUID/__init__.py | 63 ++++++++++++++++++++++++++++++++++++++++- poetry.lock | 64 +++++++++++++++++++++--------------------- requirements.txt | 2 +- 3 files changed, 95 insertions(+), 34 deletions(-) diff --git a/GenshinUID/__init__.py b/GenshinUID/__init__.py index 09557867..fc67a441 100644 --- a/GenshinUID/__init__.py +++ b/GenshinUID/__init__.py @@ -6,13 +6,14 @@ from nonebot.adapters import Bot from nonebot.matcher import Matcher from nonebot.permission import SUPERUSER from nonebot.internal.adapter import Event -from nonebot import get_driver, on_message, on_fullmatch +from nonebot import on_notice, get_driver, on_message, on_fullmatch from .client import GsClient from .auto_install import start, install from .models import Message, MessageReceive get_message = on_message(priority=999) +get_notice = on_notice(priority=999) install_core = on_fullmatch('gs一键安装', permission=SUPERUSER, block=True) start_core = on_fullmatch('启动core', permission=SUPERUSER, block=True) connect_core = on_fullmatch( @@ -22,6 +23,66 @@ driver = get_driver() gsclient: Optional[GsClient] = None +@get_notice.handle() +async def get_notice_message(bot: Bot, ev: Event): + if gsclient is None or not gsclient.is_alive: + return await connect() + + raw_data = ev.dict() + logger.debug(raw_data) + + try: + user_id = str(ev.get_user_id()) + except ValueError: + user_id = '未知' + + group_id = None + sp_user_type = None + sp_bot_id = None + self_id = str(bot.self_id) + msg_id = '' + pm = 6 + + if await SUPERUSER(bot, ev): + pm = 1 + + if 'group_id' in raw_data: + group_id = str(raw_data['group_id']) + + if 'user_id' in raw_data: + user_id = str(raw_data['user_id']) + + if sp_bot_id: + bot_id = sp_bot_id + else: + bot_id = ev.__class__.__module__.split('.')[2] + + user_type = 'group' if group_id else 'direct' + + if 'notice_type' in raw_data and raw_data['notice_type'] in [ + 'group_upload', + 'offline_file', + ]: + val = raw_data['file']['url'] + name = raw_data['file']['name'] + message = [Message('file', f'{name}|{val}')] + else: + return + + msg = MessageReceive( + bot_id=bot_id, + bot_self_id=self_id, + user_type=sp_user_type if sp_user_type else user_type, + group_id=group_id, + user_id=user_id, + content=message, + msg_id=msg_id, + user_pm=pm, + ) + logger.info(f'【发送】[gsuid-core]: {msg.bot_id}') + await gsclient._input(msg) + + @get_message.handle() async def send_char_adv(bot: Bot, ev: Event): if gsclient is None or not gsclient.is_alive: diff --git a/poetry.lock b/poetry.lock index 9a2ec816..3ef57d13 100644 --- a/poetry.lock +++ b/poetry.lock @@ -276,47 +276,47 @@ files = [ [[package]] name = "msgspec" -version = "0.13.1" +version = "0.14.0" description = "A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML." category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "msgspec-0.13.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:a07a50afb119728e4969ab58602985549b8b9af6cf565873fad28365eb7dbf7b"}, - {file = "msgspec-0.13.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:014e6e0b01946528f609102c5624749501f63ebdeba386855948185288bc299d"}, - {file = "msgspec-0.13.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ea1d6de944dd2d369186ce9f3d98119980427fd8fba0788d819d775fe0440442"}, - {file = "msgspec-0.13.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:037ff80d956bb13fc8c221a386f7ba97f6e55d0dc84f4bfe92226df570140802"}, - {file = "msgspec-0.13.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:8f0679fbafb889e4165bf49c2afd342716dcee2fe13de3777f1613c09740f304"}, - {file = "msgspec-0.13.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:99d239343d2b78ad139277067e727ad573445eec6b7ba113e4b987e15728d9d4"}, - {file = "msgspec-0.13.1-cp310-cp310-win_amd64.whl", hash = "sha256:88466f804b817151cbff9e53d698f86a9280b0d00896302abb528be01c46701a"}, - {file = "msgspec-0.13.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:494de96dc6ad90c2f3ba96130591ade518dfd019be767e6030c73ea3e9eb6df9"}, - {file = "msgspec-0.13.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:b8853fdf1c44cb874c786133ce1062b6d9a484e0fa48f7174035eb506f462042"}, - {file = "msgspec-0.13.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ac902ccdfa4574498342d06f4c49bfa60317724737985b2fc954e8c8eb009910"}, - {file = "msgspec-0.13.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7b0e594996a042fb6dcd9839094b6ef8768e7707bf1567e4d61cbf07c1d12f24"}, - {file = "msgspec-0.13.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:2d32dedfeb5646ac339eb4602886861756f050c6307e2177b7c68f5084519069"}, - {file = "msgspec-0.13.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:de920ff863aceef8304a1c5c3855f089782429f6fdbfea1321061f37e4ba418a"}, - {file = "msgspec-0.13.1-cp311-cp311-win_amd64.whl", hash = "sha256:36b919dad8cbf98d1e2b3d829bf26fbe64205a08ee1caa6988581e5850bcb6b1"}, - {file = "msgspec-0.13.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:30c80380bfe3a03b2e968f08bdbec8a9fc1619cd2555cc8334774c475296faaa"}, - {file = "msgspec-0.13.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:0e12db829b670159780d4483248c5099b99cc487f3c134f2d3e6ce59fa18ce67"}, - {file = "msgspec-0.13.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:aa7febe37689642a1a2ccdeecf3a8b820ea043cd142438bd0a88714c982555a0"}, - {file = "msgspec-0.13.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:317ec8e80cf919c42b6defb375e12ad49af649238327d0abaed980c4d72a7bea"}, - {file = "msgspec-0.13.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:d51cdd579b632e3686c14eee9948aeba056ea969b85b60e09aa9811cea3524cd"}, - {file = "msgspec-0.13.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:348415004e907c856e22884485c9f91dc8f39317ce365b0881a08ac35f234afe"}, - {file = "msgspec-0.13.1-cp38-cp38-win_amd64.whl", hash = "sha256:b80b58d8fa70f881701a3bff50661327b4f5a50441d33386fac95a94eb3cad1d"}, - {file = "msgspec-0.13.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:96f7898b4433a2570636cf0659ac7cedd1b753f0a108fa0ff82a813a830c5a98"}, - {file = "msgspec-0.13.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:fae7c7e6f7715cebc34ce616b078dc2c021651115915d0c2ea507d9c9074e34d"}, - {file = "msgspec-0.13.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:050af5e263eece6a16c07ba651ab83208acccfccc5ab8b47fa6cf99c135f01a9"}, - {file = "msgspec-0.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e143da1561b6a766c2fccdb9c487dfcf1d56c8c1b9c8c8c5c3e322f02fbb8c11"}, - {file = "msgspec-0.13.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:59e572b78da8264b2ce3dbb65bec6a4a65cb355046b0d5fc16df24626e889947"}, - {file = "msgspec-0.13.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:bf92cbef573127966cccce71eb9368a6ce36c847ee128e048c7c04724daae855"}, - {file = "msgspec-0.13.1-cp39-cp39-win_amd64.whl", hash = "sha256:358da53e870d8bdb890b27c2cd9a670bc17c1d4330908d3fb6e00dcdc8d9c54c"}, - {file = "msgspec-0.13.1.tar.gz", hash = "sha256:b252174d33c7d7885e5efe8009147f09da4bf6655b86dba9128a2a4d4c1fb6ee"}, + {file = "msgspec-0.14.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f001981317161efd31703dfe2dbccb65feba2222baedf1e1d0d3fbc4e4481d4a"}, + {file = "msgspec-0.14.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0e06dc68ccd9a456f21abf0dbcbe3d1ed00aa53f39fd01eb1f226e2e98d6e49f"}, + {file = "msgspec-0.14.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e497794d5df290911fa6b38682788e3ebee48ec9ed33b0ef5f1f9c2ac7011f45"}, + {file = "msgspec-0.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9a53047a5bbeb9f04e78990a2d17a2735c15744be13246e2c3a625db0941887d"}, + {file = "msgspec-0.14.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:a7a89677eae142c155c51d87c1df73fc5333db7cff1e08af8976aeaab2c81114"}, + {file = "msgspec-0.14.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:18a5724546fd883a575b46e26fd81d37b47b66278e89e9610a5c87aea4fdebfc"}, + {file = "msgspec-0.14.0-cp310-cp310-win_amd64.whl", hash = "sha256:f8cca6587fe94b6998151d15c05bf97bbbd4ab47ebf57b18ed49d20bb2a1713d"}, + {file = "msgspec-0.14.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c8699dbcc1eef9496bbc0d098667a0fc19041ba1c3a74af532244a5048db19ab"}, + {file = "msgspec-0.14.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:2e46843d258c3043c4807649710c20a34c37b9b91c6cd78684575f78283ec873"}, + {file = "msgspec-0.14.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3e29c330a183d2a015ee0edf8d4799540aec0ab9ffb14426c637cf1f121ed652"}, + {file = "msgspec-0.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:89f5c94f72bed3d3b6e9252b903391fb584759d1cecb607b4788392ad264fad2"}, + {file = "msgspec-0.14.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:86da8fdc94f0a38c188cb9f896174e0ba9bb474eb6b4c2937ef96075dcc76e52"}, + {file = "msgspec-0.14.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:21ee98a51930ccf57a6b16b55a1049d8cc358315196aae6c621f3d93cc25714d"}, + {file = "msgspec-0.14.0-cp311-cp311-win_amd64.whl", hash = "sha256:02e5f46b3d03a0b08bbfcd0bad9595dc732b505556cd2a7f9f01ba5b3355ae7c"}, + {file = "msgspec-0.14.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:7de7ae6d69a2d08bacab29727e594220788c5a9ae6b0bd1fddd966fa70b8cc1c"}, + {file = "msgspec-0.14.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:f674712b5f75bfbb45328b3953dff8df1ff50acc16468d7a7916424266af9cf5"}, + {file = "msgspec-0.14.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4b59025a865120703a3e51da79f7ff50aee674003317d3046352f806fd5e7d28"}, + {file = "msgspec-0.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6866a184a408d40d1098ff922b9592beca53ae9b90495f34ebb78a2d23a47dac"}, + {file = "msgspec-0.14.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:f972fc150f5a397e4df9aa369a21b3cc733d588855aa27d603977463cd50c983"}, + {file = "msgspec-0.14.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b3d0433dbf09a1ed8b197d0809d513c5f11de62cca50b1b9ac2b6d72e602ab4e"}, + {file = "msgspec-0.14.0-cp38-cp38-win_amd64.whl", hash = "sha256:e8da19d4a46f3fde25e2c32e798785716df873d29a4ca763d8becf3715c20efc"}, + {file = "msgspec-0.14.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:8b4798f9ff27aea6cc4edf072ec735c95e42a9ba499fef0120f09c52dfc469cd"}, + {file = "msgspec-0.14.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:1431df375e36f678d0d9b802c1792c904e70c315002c08ecf85ff1007cabcdb7"}, + {file = "msgspec-0.14.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:15d910a223737735196297dd4d26b54679e2ac2b95beaef3837ff918a13be7db"}, + {file = "msgspec-0.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6d8b4969739f60fc3751e1c73c4cf31f061654a00b452675cbb22ea99f06c2df"}, + {file = "msgspec-0.14.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:a8fee0ffa0753f632cd94fa304a2e9ca9c92f9695fdb2ea160ac048dc278d008"}, + {file = "msgspec-0.14.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a15d07d9daeb7daad32b19c194913452ba14748a37d230bcee45e118767b7b8e"}, + {file = "msgspec-0.14.0-cp39-cp39-win_amd64.whl", hash = "sha256:f0f178d36eb91ba99003bd5e0bae4c1cb834f0d86b4ae9b5a8e88d4ef544ba86"}, + {file = "msgspec-0.14.0.tar.gz", hash = "sha256:eef6506652f6d5968371ab3ed70895dcea39207246feb83e386640289d7d129f"}, ] [package.extras] -dev = ["coverage", "furo", "gcovr", "ipython", "msgpack", "mypy", "pre-commit", "pyright", "pytest", "pyyaml", "sphinx", "sphinx-copybutton", "sphinx-design", "tomli", "tomli-w"] +dev = ["attrs", "coverage", "furo", "gcovr", "ipython", "msgpack", "mypy", "pre-commit", "pyright", "pytest", "pyyaml", "sphinx", "sphinx-copybutton", "sphinx-design", "tomli", "tomli-w"] doc = ["furo", "ipython", "sphinx", "sphinx-copybutton", "sphinx-design"] -test = ["msgpack", "mypy", "pyright", "pytest", "pyyaml", "tomli", "tomli-w"] +test = ["attrs", "msgpack", "mypy", "pyright", "pytest", "pyyaml", "tomli", "tomli-w"] toml = ["tomli", "tomli-w"] yaml = ["pyyaml"] diff --git a/requirements.txt b/requirements.txt index c717d60d..74a8b439 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ gitdb==4.0.10 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" gitpython==3.1.31 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" idna==3.4 ; python_full_version >= "3.8.1" and python_version < "4.0" loguru==0.6.0 ; python_full_version >= "3.8.1" and python_version < "4.0" -msgspec==0.13.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" +msgspec==0.14.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" multidict==6.0.4 ; python_full_version >= "3.8.1" and python_version < "4.0" nonebot2==2.0.0rc4 ; python_full_version >= "3.8.1" and python_version < "4.0" pillow==9.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"