From fdf16ff9a3a90f577e813d3562b875b084f3244c Mon Sep 17 00:00:00 2001 From: mobyw <44370805+mobyw@users.noreply.github.com> Date: Sun, 16 Apr 2023 15:23:21 +0800 Subject: [PATCH 1/2] :bug: Fix TypeError in call of `escape_tag` --- LittlePaimon/utils/logger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LittlePaimon/utils/logger.py b/LittlePaimon/utils/logger.py index f709396..79e40f6 100644 --- a/LittlePaimon/utils/logger.py +++ b/LittlePaimon/utils/logger.py @@ -11,13 +11,13 @@ class logger: @staticmethod def info(command: str, info: str = '', param: Dict[str, any] = None, result: str = '', result_type: bool = True): - param_str = ' '.join([f'{k}{escape_tag(v)}' for k, v in param.items()]) if param else '' + param_str = ' '.join([f'{k}{escape_tag(str(v))}' for k, v in param.items()]) if param else '' result_str = f'{escape_tag(result)}' if result_type else f'{escape_tag(result)}' if result else '' nb_logger.opt(colors=True).info(f'[{command}]{info}{param_str}{result_str}') @staticmethod def success(command: str, info: str = '', param: Dict[str, any] = None, result: str = ''): - param_str = ' '.join([f'{k}{escape_tag(v)}' for k, v in param.items()]) if param else '' + param_str = ' '.join([f'{k}{escape_tag(str(v))}' for k, v in param.items()]) if param else '' result_str = f'{escape_tag(result)}' if result else '' nb_logger.opt(colors=True).success(f'[{command}]{info}{param_str}{result_str}') From f0f5910d1018b946dc1b0ea394e7809548264d2c Mon Sep 17 00:00:00 2001 From: mobyw <44370805+mobyw@users.noreply.github.com> Date: Sun, 16 Apr 2023 16:09:17 +0800 Subject: [PATCH 2/2] :bug: Fix error in qq/group with search turned off --- .../plugins/NoticeAndRequest/__init__.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/LittlePaimon/plugins/NoticeAndRequest/__init__.py b/LittlePaimon/plugins/NoticeAndRequest/__init__.py index e20216b..5da3ba6 100644 --- a/LittlePaimon/plugins/NoticeAndRequest/__init__.py +++ b/LittlePaimon/plugins/NoticeAndRequest/__init__.py @@ -10,7 +10,8 @@ from nonebot.params import CommandArg, ArgPlainText from nonebot.adapters.onebot.v11 import Bot, Message, MessageEvent, PrivateMessageEvent, FriendRequestEvent, \ GroupRequestEvent, \ RequestEvent, NoticeEvent, \ - GroupIncreaseNoticeEvent, FriendAddNoticeEvent, GroupMessageEvent + GroupIncreaseNoticeEvent, FriendAddNoticeEvent, GroupMessageEvent, \ + ActionFailed from nonebot.typing import T_State from LittlePaimon.config import config as bot_config @@ -105,7 +106,10 @@ async def _(event: PrivateMessageEvent, bot: Bot, state: T_State, id_: str = Arg @requests.handle() async def _(bot: Bot, event: FriendRequestEvent): done[f'add_friend_{event.user_id}'] = datetime.datetime.now() - user_info = await bot.get_stranger_info(user_id=event.user_id) + try: + user_info = await bot.get_stranger_info(user_id=event.user_id) + except ActionFailed: + user_info = {'nickname': '未知'} base_msg = f'{user_info["nickname"]}({event.user_id})请求添加好友,验证信息为"{event.comment or "无"}"' if bot_config.auto_add_friend: await asyncio.sleep(random.randint(10, 20)) @@ -121,8 +125,14 @@ async def _(bot: Bot, event: FriendRequestEvent): @requests.handle() async def _(bot: Bot, event: GroupRequestEvent): done[f'add_group_{event.group_id}'] = datetime.datetime.now() - user_info = await bot.get_stranger_info(user_id=event.user_id) - group_info = await bot.get_group_info(group_id=event.group_id) + try: + user_info = await bot.get_stranger_info(user_id=event.user_id) + except ActionFailed: + user_info = {'nickname': '未知'} + try: + group_info = await bot.get_group_info(group_id=event.group_id) + except ActionFailed: + group_info = {'group_name': '未知'} base_msg = f'{user_info["nickname"]}({event.user_id})邀请{NICKNAME}加入群{group_info["group_name"]}({event.group_id})' if bot_config.auto_add_group or event.user_id in SUPERUSERS: await asyncio.sleep(random.randint(10, 20))