From 0efe65ce7a8dfbdb84bb5f296bf38411d690dde8 Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Mon, 14 Mar 2022 09:27:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E6=94=AF=E6=8C=81=E7=A7=81?= =?UTF-8?q?=E8=81=8A&fix=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Genshin_Paimon/player_card/__init__.py | 6 +++- .../Genshin_Paimon/user_data/__init__.py | 30 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/hoshino/modules/Genshin_Paimon/player_card/__init__.py b/hoshino/modules/Genshin_Paimon/player_card/__init__.py index 4716386..8ce0c86 100644 --- a/hoshino/modules/Genshin_Paimon/player_card/__init__.py +++ b/hoshino/modules/Genshin_Paimon/player_card/__init__.py @@ -87,7 +87,11 @@ async def my_characters(bot,ev): uid = '' if len(msg[0]) == 9 and msg[0].isdigit(): uid = msg[0] - chara = msg[1] + if len(msg) >= 2: + chara = msg[1] + else: + await bot.send(ev,'要把想查询的角色名告诉我哦!',at_sender=True) + return else: chara = msg[0] chara_name = get_id_by_alias(chara) diff --git a/hoshino/modules/Genshin_Paimon/user_data/__init__.py b/hoshino/modules/Genshin_Paimon/user_data/__init__.py index d339fc1..1ef5c30 100644 --- a/hoshino/modules/Genshin_Paimon/user_data/__init__.py +++ b/hoshino/modules/Genshin_Paimon/user_data/__init__.py @@ -1,9 +1,37 @@ -from hoshino import MessageSegment, Service +from hoshino import MessageSegment, Service, trigger, priv, CanceledException from hoshino.typing import CQEvent, Message from ..util import update_last_query_to_qq, bind_cookie +from nonebot import message_preprocessor sv = Service('原神绑定',visible=False,enable_on_default=True) +private_prefix = [] + +# support private message +@message_preprocessor +async def private_handler(bot, ev, _): + if ev.detail_type != 'private': + return + for t in trigger.chain: + for service in t.find_handler(ev): + sv = service.sv + if sv in private_prefix: + if priv.get_user_priv(ev) >= priv.NORMAL: + try: + await service.func(bot, ev) + except CanceledException: + raise + sv.logger.info( + f'Private Message {ev.message_id} triggered {service.func.__name__}.' + ) + +def support_private(sv): + def wrap(func): + private_prefix.append(sv) + return func + return wrap + +@support_private(sv) @sv.on_prefix(('原神绑定','ysb')) async def bind(bot,ev): msg = ev.message.extract_plain_text().strip().split('#')