mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
* 🎨 notice响应期添加rule
* chore(version): Update version to v0.2.3-f3e5c9e
---------
Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
80 lines
2.9 KiB
Python
80 lines
2.9 KiB
Python
import logging
|
|
|
|
from nonebot.typing import T_State
|
|
from nonebot.matcher import Matcher
|
|
from nonebot_plugin_alconna import At
|
|
from nonebot.adapters import Bot, Event
|
|
from nonebot.message import run_preprocessor
|
|
from nonebot.exception import IgnoredException
|
|
from nonebot_plugin_session import EventSession
|
|
|
|
from zhenxun.configs.config import Config
|
|
from zhenxun.utils.enum import PluginType
|
|
from zhenxun.utils.utils import FreqLimiter
|
|
from zhenxun.utils.message import MessageUtils
|
|
from zhenxun.models.ban_console import BanConsole
|
|
from zhenxun.models.group_console import GroupConsole
|
|
|
|
Config.add_plugin_config(
|
|
"hook",
|
|
"BAN_RESULT",
|
|
"才不会给你发消息.",
|
|
help="对被ban用户发送的消息",
|
|
)
|
|
|
|
_flmt = FreqLimiter(300)
|
|
|
|
|
|
# 检查是否被ban
|
|
@run_preprocessor
|
|
async def _(
|
|
matcher: Matcher, bot: Bot, event: Event, state: T_State, session: EventSession
|
|
):
|
|
if plugin := matcher.plugin:
|
|
if metadata := plugin.metadata:
|
|
extra = metadata.extra
|
|
if extra.get("plugin_type") in [PluginType.HIDDEN, PluginType.DEPENDANT]:
|
|
return
|
|
user_id = session.id1
|
|
group_id = session.id3 or session.id2
|
|
if group_id:
|
|
if user_id in bot.config.superusers:
|
|
return
|
|
if await BanConsole.is_ban(None, group_id):
|
|
logging.debug("群组处于黑名单中...", "ban_hook")
|
|
raise IgnoredException("群组处于黑名单中...")
|
|
if g := await GroupConsole.get_group(group_id):
|
|
if g.level < 0:
|
|
logging.debug("群黑名单, 群权限-1...", "ban_hook")
|
|
raise IgnoredException("群黑名单, 群权限-1..")
|
|
if user_id:
|
|
ban_result = Config.get_config("hook", "BAN_RESULT")
|
|
if user_id in bot.config.superusers:
|
|
return
|
|
if await BanConsole.is_ban(user_id, group_id):
|
|
time = await BanConsole.check_ban_time(user_id, group_id)
|
|
if time == -1:
|
|
time_str = "∞"
|
|
else:
|
|
time = abs(int(time))
|
|
if time < 60:
|
|
time_str = f"{time!s} 秒"
|
|
else:
|
|
minute = int(time / 60)
|
|
if minute > 60:
|
|
hours = minute // 60
|
|
minute %= 60
|
|
time_str = f"{hours} 小时 {minute}分钟"
|
|
else:
|
|
time_str = f"{minute} 分钟"
|
|
if time != -1 and ban_result and _flmt.check(user_id):
|
|
_flmt.start_cd(user_id)
|
|
await MessageUtils.build_message(
|
|
[
|
|
At(flag="user", target=user_id),
|
|
f"{ban_result}\n在..在 {time_str} 后才会理你喔",
|
|
]
|
|
).send()
|
|
logging.debug("用户处于黑名单中...", "ban_hook")
|
|
raise IgnoredException("用户处于黑名单中...")
|