绑定支持私聊&fix bug

This commit is contained in:
CMHopeSunshine 2022-03-14 09:27:43 +08:00
parent 257bac7edc
commit 0efe65ce7a
2 changed files with 34 additions and 2 deletions

View File

@ -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)

View File

@ -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('#')