zhenxun_bot/basic_plugins/hooks/auth_hook.py

37 lines
853 B
Python
Raw Normal View History

2022-01-05 22:32:59 +08:00
from typing import Optional
2022-11-21 20:43:41 +08:00
2022-02-19 18:20:19 +08:00
from nonebot.adapters.onebot.v11 import (
2021-11-23 21:44:59 +08:00
Bot,
MessageEvent,
2022-02-21 15:59:17 +08:00
Event,
2021-11-23 21:44:59 +08:00
)
2022-11-21 20:43:41 +08:00
from nonebot.matcher import Matcher
from nonebot.message import run_preprocessor, run_postprocessor
from nonebot.typing import T_State
2021-11-23 21:44:59 +08:00
2022-11-21 20:43:41 +08:00
from ._utils import (
set_block_limit_false,
AuthChecker,
)
2021-11-23 21:44:59 +08:00
2022-11-21 20:43:41 +08:00
# # 权限检测
2021-11-23 21:44:59 +08:00
@run_preprocessor
2022-11-21 20:43:41 +08:00
async def _(matcher: Matcher, bot: Bot, event: Event):
await AuthChecker().auth(matcher, bot, event)
2022-01-05 22:32:59 +08:00
# 解除命令block阻塞
@run_postprocessor
async def _(
2022-11-21 20:43:41 +08:00
matcher: Matcher,
exception: Optional[Exception],
bot: Bot,
event: Event,
state: T_State,
2022-01-05 22:32:59 +08:00
):
2022-02-19 18:20:19 +08:00
if not isinstance(event, MessageEvent) and matcher.plugin_name != "poke":
2022-01-05 22:32:59 +08:00
return
2022-02-19 18:20:19 +08:00
module = matcher.plugin_name
2022-01-05 22:32:59 +08:00
set_block_limit_false(event, module)