This commit is contained in:
HibiKier
2023-03-19 21:05:34 +08:00
parent f8371e7330
commit 1046815d37
36 changed files with 704 additions and 582 deletions
+28 -43
View File
@@ -1,17 +1,11 @@
from nonebot.adapters.onebot.v11 import (
ActionFailed,
Bot,
Event,
GroupMessageEvent,
MessageEvent,
PokeNotifyEvent,
)
from nonebot.adapters.onebot.v11 import ActionFailed, Bot, Event, GroupMessageEvent
from nonebot.matcher import Matcher
from nonebot.message import IgnoredException, run_preprocessor
from nonebot.typing import T_State
from configs.config import Config
from models.ban_user import BanUser
from services.log import logger
from utils.message_builder import at
from utils.utils import FreqLimiter, is_number, static_flmt
@@ -30,26 +24,19 @@ _flmt = FreqLimiter(300)
# 检查是否被ban
@run_preprocessor
async def _(matcher: Matcher, bot: Bot, event: Event, state: T_State):
if hasattr(event, "user_id") and (
(
(isinstance(event, MessageEvent) or isinstance(event, PokeNotifyEvent))
and matcher.priority not in [1, 999]
)
or matcher.plugin_name in other_limit_plugins
user_id = getattr(event, "user_id", None)
group_id = getattr(event, "group_id", None)
if user_id and (
matcher.priority not in [1, 999] or matcher.plugin_name in other_limit_plugins
):
try:
if (
await BanUser.is_super_ban(event.user_id)
and str(event.user_id) not in bot.config.superusers
):
raise IgnoredException("用户处于超级黑名单中")
except AttributeError:
pass
if (
await BanUser.is_ban(event.user_id)
and str(event.user_id) not in bot.config.superusers
await BanUser.is_super_ban(user_id)
and str(user_id) not in bot.config.superusers
):
time = await BanUser.check_ban_time(event.user_id)
logger.debug(f"用户处于超级黑名单中...", "HOOK", user_id, group_id)
raise IgnoredException("用户处于超级黑名单中")
if await BanUser.is_ban(user_id) and str(user_id) not in bot.config.superusers:
time = await BanUser.check_ban_time(user_id)
if isinstance(time, int):
time = abs(int(time))
if time < 60:
@@ -59,40 +46,38 @@ async def _(matcher: Matcher, bot: Bot, event: Event, state: T_State):
else:
time = str(time) + " 分钟"
if isinstance(event, GroupMessageEvent):
if not static_flmt.check(event.user_id):
if not static_flmt.check(user_id):
logger.debug(f"用户处于黑名单中...", "HOOK", user_id, group_id)
raise IgnoredException("用户处于黑名单中")
static_flmt.start_cd(event.user_id)
static_flmt.start_cd(user_id)
if matcher.priority != 999:
try:
ban_result = Config.get_config("hook", "BAN_RESULT")
if (
ban_result
and _flmt.check(event.user_id)
and _flmt.check(user_id)
and matcher.plugin_name not in ignore_rst_module
):
_flmt.start_cd(event.user_id)
_flmt.start_cd(user_id)
await bot.send_group_msg(
group_id=event.group_id,
message=at(event.user_id)
message=at(user_id)
+ ban_result
+ f" 在..在 {time} 后才会理你喔",
)
except ActionFailed:
pass
else:
if not static_flmt.check(event.user_id):
if not static_flmt.check(user_id):
logger.debug(f"用户处于黑名单中...", "HOOK", user_id, group_id)
raise IgnoredException("用户处于黑名单中")
static_flmt.start_cd(event.user_id)
static_flmt.start_cd(user_id)
if matcher.priority != 999:
try:
ban_result = Config.get_config("hook", "BAN_RESULT")
if ban_result and matcher.plugin_name not in ignore_rst_module:
await bot.send_private_msg(
user_id=event.user_id,
message=at(event.user_id)
+ ban_result
+ f" 在..在 {time}后才会理你喔",
)
except ActionFailed:
pass
ban_result = Config.get_config("hook", "BAN_RESULT")
if ban_result and matcher.plugin_name not in ignore_rst_module:
await bot.send_private_msg(
user_id=user_id,
message=at(user_id) + ban_result + f" 在..在 {time}后才会理你喔",
)
logger.debug(f"用户处于黑名单中...", "HOOK", user_id, group_id)
raise IgnoredException("用户处于黑名单中")