Files
nonebot-plugin-tetris-stats/nonebot_plugin_tetris_stats/games/__init__.py
2024-05-16 05:59:18 +08:00

41 lines
1.3 KiB
Python

from typing import Any
from nonebot.adapters import Bot
from nonebot.exception import FinishedException
from nonebot.matcher import Matcher
from nonebot.message import run_postprocessor
from nonebot_plugin_alconna import AlcMatches, AlconnaMatcher, At
from ..utils.exception import MessageFormatError, NeedCatchError
def add_default_handlers(matcher: type[AlconnaMatcher]) -> None:
@matcher.assign('query')
async def _(bot: Bot, matcher: Matcher, target: At):
if isinstance(target, At) and target.target == bot.self_id:
await matcher.finish('不能查询bot的信息')
@matcher.handle()
async def _(matcher: Matcher, account: MessageFormatError):
await matcher.finish(str(account))
@matcher.handle()
async def _(matcher: Matcher, matches: AlcMatches):
if matches.head_matched and matches.options != {} or matches.main_args == {}:
await matcher.finish(
(f'{matches.error_info!r}\n' if matches.error_info is not None else '')
+ f'输入"{matches.header_result} --help"查看帮助'
)
@matcher.handle()
def _(other: Any): # noqa: ANN401, ARG001
raise FinishedException
from . import tetrio, top, tos # noqa: F401, E402
@run_postprocessor
async def _(matcher: Matcher, exception: NeedCatchError):
await matcher.send(str(exception))