From 1a2a0c792d8dc1c92418049eec29bd897ee378df Mon Sep 17 00:00:00 2001 From: ieew Date: Sun, 6 Mar 2022 19:21:40 +0800 Subject: [PATCH 1/2] modified: nonebot/adapters/mirai2/adapter.py modified: nonebot/adapters/mirai2/message.py modified: nonebot/adapters/mirai2/utils.py --- nonebot/adapters/mirai2/adapter.py | 10 ++++++---- nonebot/adapters/mirai2/message.py | 2 +- nonebot/adapters/mirai2/utils.py | 19 ++++++++++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/nonebot/adapters/mirai2/adapter.py b/nonebot/adapters/mirai2/adapter.py index 93612f2..7389fb5 100644 --- a/nonebot/adapters/mirai2/adapter.py +++ b/nonebot/adapters/mirai2/adapter.py @@ -53,11 +53,11 @@ def setup(self) -> None: async def start_ws_client(self): for qq in self.mirai_config.mirai_qq: self.tasks.append(asyncio.create_task(self._client(qq))) + else: + await asyncio.wait(self.tasks) async def stop_ws_client(self): - for task in self.tasks: - if not task.done(): - task.cancel() + pass async def _client(self, self_qq: int): request = Request( @@ -92,16 +92,18 @@ async def _client(self, self_qq: int): except ConnectionRefusedError as e: log.warn(f"connection error ({self_qq}):{e} ") break + except: + log.error(traceback.format_exc()) await asyncio.sleep(3) async def ws_event(self, ws: WebSocket, self_qq: int, data: dict): bot = Bot(self, str(self_qq)) self.bot_connect(bot) + self.connections[str(self_qq)] = ws while True: data = await ws.receive() json_data = json.loads(data) - print(data) if int(json_data.get("syncId") or "0") >= 0: SyncIDStore.add_response(json_data) continue diff --git a/nonebot/adapters/mirai2/message.py b/nonebot/adapters/mirai2/message.py index a9c490b..b5a4222 100644 --- a/nonebot/adapters/mirai2/message.py +++ b/nonebot/adapters/mirai2/message.py @@ -253,7 +253,7 @@ def Dice(cls, value: int): :说明: 掷骰子消息 - + :参数: * ``value: int``: 骰子的值 diff --git a/nonebot/adapters/mirai2/utils.py b/nonebot/adapters/mirai2/utils.py index 3e92055..54e3dab 100644 --- a/nonebot/adapters/mirai2/utils.py +++ b/nonebot/adapters/mirai2/utils.py @@ -70,15 +70,16 @@ def process_at(bot: "Bot", event: GroupMessage) -> GroupMessage: def process_nick(bot: "Bot", event: GroupMessage) -> GroupMessage: plain = event.message_chain.extract_first(MessageType.PLAIN) - if plain is not None and len(bot.config.nickname): - text = str(plain) - nick_regex = '|'.join(filter(lambda x: x, bot.config.nickname)) - matched = re.search(rf"^({nick_regex})([\s,,]*|$)", text, re.IGNORECASE) - if matched is not None: - event.to_me = True - nickname = matched.group(1) - Log.info(f'User is calling me {nickname}') - plain.data['text'] = text[matched.end():] + if plain is not None: + if len(bot.config.nickname): + text = str(plain) + nick_regex = '|'.join(filter(lambda x: x, bot.config.nickname)) + matched = re.search(rf"^({nick_regex})([\s,,]*|$)", text, re.IGNORECASE) + if matched is not None: + event.to_me = True + nickname = matched.group(1) + Log.info(f'User is calling me {nickname}') + plain.data['text'] = text[matched.end():] event.message_chain.insert(0, plain) return event From 2e5d4cb560554945e8437292399ca2c410d6330f Mon Sep 17 00:00:00 2001 From: ieew Date: Sun, 6 Mar 2022 21:24:58 +0800 Subject: [PATCH 2/2] modified: pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6c6d2f5..6d64d5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot_adapter_mirai2" -version = "0.0.7" +version = "0.0.9" description = "兼容 MiraiApiHttp2.x 的 nonebot2_adapter" authors = ["ieew "] license = "AGPL-3.0"