From f849f9d44a23a32430d0ed40ec91c0d313268650 Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Sun, 18 Dec 2022 22:06:02 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20`Wiki`=E6=9F=A5=E8=AF=A2=E6=9D=A1?= =?UTF-8?q?=E7=9B=AE=E5=A4=AA=E5=A4=9A=E6=97=B6=E4=BD=BF=E7=94=A8=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=BD=AC=E5=8F=91=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/plugins/Paimon_Wiki/__init__.py | 51 ++++++++++++-------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/LittlePaimon/plugins/Paimon_Wiki/__init__.py b/LittlePaimon/plugins/Paimon_Wiki/__init__.py index d2df278..b1f7999 100644 --- a/LittlePaimon/plugins/Paimon_Wiki/__init__.py +++ b/LittlePaimon/plugins/Paimon_Wiki/__init__.py @@ -202,12 +202,12 @@ async def _(state: T_State, regex_dict: dict = RegexDict()): elif name.endswith('圣遗物'): state['type'] = '圣遗物图鉴' name = name[:-3] - elif name.endswith(('七圣召唤', '原牌', '卡牌')): + elif name.endswith(('七圣召唤', '原牌', '卡牌', '七圣')): state['type'] = '七圣召唤图鉴' name = name.replace('七圣召唤', '').replace('原牌', '').replace('卡牌', '') else: state['type'] = type - elif type in {'参考面板', '收益曲线'}: + else: state['type'] = type if name: state['name'] = Message(name) @@ -218,7 +218,7 @@ week_str = ['周一', '周二', '周三', '周四', '周五', '周六'] @total_wiki.got('name', prompt=Message.template('你要查询谁的{type}呢?'), parameterless=cancel) -async def _(event: MessageEvent, state: T_State, type: str = Arg('type'), name: str = ArgPlainText('name')): +async def _(bot: Bot, event: MessageEvent, state: T_State, type: str = Arg('type'), name: str = ArgPlainText('name')): if not name: if state['times'] == 2: await total_wiki.finish('旅行者似乎不太能理解,下次再问我吧' + MessageSegment.face(146)) @@ -270,8 +270,7 @@ async def _(event: MessageEvent, state: T_State, type: str = Arg('type'), name: await total_wiki.finish( MessageSegment.image(API[type].format(proxy=config.github_proxy, name=final_name))) except ActionFailed: - await total_wiki.finish( - MessageBuild.Text(f'{final_name}的{type}发送失败,可能是网络问题或者不存在该资源')) + await total_wiki.finish(f'{final_name}的{type}发送失败,可能是网络问题或者不存在该资源') matches = get_match_alias(name, ['角色', '武器', '原魔', '圣遗物']) if m := await get_match_card(name): matches['七圣召唤'] = m @@ -286,18 +285,33 @@ async def _(event: MessageEvent, state: T_State, type: str = Arg('type'), name: await total_wiki.finish( MessageSegment.image(API[type].format(proxy=config.github_proxy, name=final_name))) except ActionFailed: - await total_wiki.finish( - MessageBuild.Text(f'{final_name}的{type}发送失败,可能是网络问题或者不存在该资源')) + await total_wiki.finish(f'{final_name}的{type}发送失败,可能是网络问题或者不存在该资源') else: - msg = f'你要查询的{type}是:\n' - index = 1 - for key, value in matches.items(): - for v in value: - msg += f'{index}.{v}({key})\n' if len(matches) > 1 else f'{index}.{v}\n' - index += 1 - # msg += '\n'.join([f'{i}({key})' if len(matches) > 1 else f'{i}' for i in value]) + '\n' - msg += '回答\"序号\"查询或回答\"取消\"取消查询' - await total_wiki.send(msg) + send_flag = False + if sum(len(value) for value in matches.values()) >= 15 and isinstance(event, (PrivateMessageEvent, GroupMessageEvent)): + msg = [ + {'type': 'node', + 'data': {'name': NICKNAME, 'uin': event.self_id, 'content': f'{type}:\n' + '\n'.join(names)}} + for type, names in matches.items()] + msg.insert(0, {'type': 'node', 'data': {'name': NICKNAME, 'uin': event.self_id, 'content': f'你要查询哪个的{type}呢?'}}) + msg.append({'type': 'node', 'data': {'name': NICKNAME, 'uin': event.self_id, 'content': '回答\"序号\"查询或回答\"取消\"取消查询'}}) + try: + send_flag = True + if isinstance(event, GroupMessageEvent): + await bot.call_api('send_group_forward_msg', group_id=event.group_id, messages=msg) + elif isinstance(event, PrivateMessageEvent): + await bot.call_api('send_private_forward_msg', user_id=event.user_id, messages=msg) + except ActionFailed: + send_flag = False + if not send_flag: + index = 1 + msg = f'你要查询的{type}是:\n' + for key, value in matches.items(): + for v in value: + msg += f'{index}.{v}({key})\n' if len(matches) > 1 else f'{index}.{v}\n' + index += 1 + msg += '回答\"序号\"查询或回答\"取消\"取消查询' + await total_wiki.send(msg) state['matches'] = matches @@ -328,8 +342,7 @@ async def _(state: T_State, matches: dict = Arg('matches'), choice: str = ArgPla await total_wiki.finish( MessageSegment.image(API[type].format(proxy=config.github_proxy, name=final_name))) except ActionFailed: - await total_wiki.finish( - MessageBuild.Text(f'{final_name}的{type}发送失败,可能是网络问题或者不存在该资源')) + await total_wiki.finish(f'{final_name}的{type}发送失败,可能是网络问题或者不存在该资源') elif state['times'] == 2: await total_wiki.finish(f'旅行者似乎不太能理解,下次再问我吧{MessageSegment.face(146)}') else: @@ -352,7 +365,7 @@ async def _(bot: Bot, event: MessageEvent): elif isinstance(event, PrivateMessageEvent): await bot.call_api('send_private_forward_msg', user_id=event.user_id, messages=msg) else: - msg = '七圣召唤卡牌列表:' + msg = '七圣召唤卡牌列表:\n' for type, cards in result.items(): msg += f'{type}:\n' + '\n'.join([' '.join(cards[i:i + 3]) for i in range(0, len(cards), 3)]) + '\n' await card_wiki_list.send(msg)