From 192f880a6d12016d6e333b0b95f486ccf1c57346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wuyi=E6=97=A0=E7=96=91?= <444835641@qq.com> Date: Wed, 29 Mar 2023 23:05:20 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0`at=5Flist`?= =?UTF-8?q?=E5=92=8C`reply`=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GenshinUID/__init__.py | 9 +++++++++ GenshinUID/client.py | 20 ++++++++++++++++---- poetry.lock | 20 ++++++++++---------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/GenshinUID/__init__.py b/GenshinUID/__init__.py index fd3a0021..459bdef0 100644 --- a/GenshinUID/__init__.py +++ b/GenshinUID/__init__.py @@ -45,6 +45,13 @@ async def get_gs_msg(ev): else: bot_id = 'onebot' + try: + if ev.sender['role'] == 'owner' or ev.sender['role'] == 'admin': + pm = 2 + except Exception as e: + logger.warning(e) + pm = 3 + # 处理消息 for _msg in messages: if _msg.type == 'text': @@ -60,6 +67,8 @@ async def get_gs_msg(ev): message.append(Message('image', _msg.data['url'])) elif _msg.type == 'at': message.append(Message('at', _msg.data['qq'])) + elif _msg.type == 'reply': + message.append(Message('reply', _msg.data['id'])) if not message: return diff --git a/GenshinUID/client.py b/GenshinUID/client.py index a7e59d91..5601f481 100644 --- a/GenshinUID/client.py +++ b/GenshinUID/client.py @@ -25,7 +25,9 @@ class GsClient: cls.is_alive = True cls.ws_url = f'ws://{IP}:{PORT}/ws/{BOT_ID}' logger.info(f'Bot_ID: {BOT_ID}连接至[gsuid-core]: {self.ws_url}...') - cls.ws = await websockets.client.connect(cls.ws_url, max_size=2**26) + cls.ws = await websockets.client.connect( + cls.ws_url, max_size=2**26, open_timeout=60, ping_timeout=60 + ) logger.info(f'与[gsuid-core]成功连接! Bot_ID: {BOT_ID}') cls.msg_list = asyncio.queues.Queue() return self @@ -43,6 +45,11 @@ class GsClient: ) # 解析消息 if msg.bot_id == 'NoneBot2': + if msg.content: + _data = msg.content[0] + if _data.type and _data.type.startswith('log'): + _type = _data.type.split('_')[-1].lower() + getattr(logger, _type)(_data.data) continue bot = hoshino_bot @@ -51,6 +58,7 @@ class GsClient: image: Optional[str] = None node = [] file = '' + at_list = [] if msg.content: for _c in msg.content: if _c.data: @@ -58,13 +66,12 @@ class GsClient: content += _c.data elif _c.type == 'image': image = _c.data - elif _c.type and _c.type.startswith('log'): - _type = _c.type.split('_')[-1].lower() - getattr(logger, _type)(_c.data) elif _c.type == 'node': node = _c.data elif _c.type == 'file': file = _c.data + elif _c.type == 'at': + at_list.append(_c.data) else: pass @@ -84,6 +91,7 @@ class GsClient: node, file, ids, + at_list, msg.target_id, msg.target_type, ) @@ -140,6 +148,7 @@ async def onebot_send( node: Optional[List[Dict]], file: Optional[str], bot_self_id: Optional[str], + at_list: Optional[List[str]], target_id: Optional[str], target_type: Optional[str], ): @@ -147,6 +156,9 @@ async def onebot_send( result_image = f'[CQ:image,file={image}]' if image else '' content = content if content else '' result_msg = content + result_image + if at_list and target_type == 'group': + for at in at_list: + result_msg += f'[CQ:at,qq={at}]' if file: file_name, file_content = file.split('|') diff --git a/poetry.lock b/poetry.lock index eb44eabc..f2fdc4c4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -89,14 +89,14 @@ files = [ [[package]] name = "filelock" -version = "3.10.6" +version = "3.10.7" description = "A platform independent file lock." category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "filelock-3.10.6-py3-none-any.whl", hash = "sha256:52f119747b2b9c4730dac715a7b1ab34b8ee70fd9259cba158ee53da566387ff"}, - {file = "filelock-3.10.6.tar.gz", hash = "sha256:409105becd604d6b176a483f855e7e8903c5cb2873e47f2c64f66a370c046aaf"}, + {file = "filelock-3.10.7-py3-none-any.whl", hash = "sha256:bde48477b15fde2c7e5a0713cbe72721cb5a5ad32ee0b8f419907960b9d75536"}, + {file = "filelock-3.10.7.tar.gz", hash = "sha256:892be14aa8efc01673b5ed6589dbccb95f9a8596f0507e232626155495c18105"}, ] [package.extras] @@ -549,14 +549,14 @@ files = [ [[package]] name = "setuptools" -version = "67.6.0" +version = "67.6.1" description = "Easily download, build, install, upgrade, and uninstall Python packages" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "setuptools-67.6.0-py3-none-any.whl", hash = "sha256:b78aaa36f6b90a074c1fa651168723acbf45d14cb1196b6f02c0fd07f17623b2"}, - {file = "setuptools-67.6.0.tar.gz", hash = "sha256:2ee892cd5f29f3373097f5a814697e397cf3ce313616df0af11231e2ad118077"}, + {file = "setuptools-67.6.1-py3-none-any.whl", hash = "sha256:e728ca814a823bf7bf60162daf9db95b93d532948c4c0bea762ce62f60189078"}, + {file = "setuptools-67.6.1.tar.gz", hash = "sha256:257de92a9d50a60b8e22abfcbb771571fde0dbf3ec234463212027a4eeecbe9a"}, ] [package.extras] @@ -590,14 +590,14 @@ files = [ [[package]] name = "tomlkit" -version = "0.11.6" +version = "0.11.7" description = "Style preserving TOML library" category = "dev" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "tomlkit-0.11.6-py3-none-any.whl", hash = "sha256:07de26b0d8cfc18f871aec595fda24d95b08fef89d147caa861939f37230bf4b"}, - {file = "tomlkit-0.11.6.tar.gz", hash = "sha256:71b952e5721688937fb02cf9d354dbcf0785066149d2855e44531ebdd2b65d73"}, + {file = "tomlkit-0.11.7-py3-none-any.whl", hash = "sha256:5325463a7da2ef0c6bbfefb62a3dc883aebe679984709aee32a317907d0a8d3c"}, + {file = "tomlkit-0.11.7.tar.gz", hash = "sha256:f392ef70ad87a672f02519f99967d28a4d3047133e2d1df936511465fbb3791d"}, ] [[package]]