mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 08:39:59 +08:00
refactor code
This commit is contained in:
@@ -3,7 +3,13 @@ from nonebot.matcher import Matcher
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.exception import IgnoredException
|
||||
from nonebot.message import run_preprocessor
|
||||
from nonebot.adapters.cqhttp import Event, Bot, GroupMessageEvent, PrivateMessageEvent, MessageEvent
|
||||
from nonebot.adapters.cqhttp import (
|
||||
Event,
|
||||
Bot,
|
||||
GroupMessageEvent,
|
||||
PrivateMessageEvent,
|
||||
MessageEvent,
|
||||
)
|
||||
from configs.config import plugins2info_dict
|
||||
from utils.utils import FreqLimiter
|
||||
from models.ban_user import BanUser
|
||||
@@ -19,7 +25,6 @@ from .parser import npm_parser
|
||||
export = export()
|
||||
export.block_plugin = block_plugin
|
||||
export.unblock_plugin = unblock_plugin
|
||||
export.unblock_plugin = unblock_plugin
|
||||
export.get_group_plugin_list = get_group_plugin_list
|
||||
|
||||
# 注册 shell_like 事件响应器
|
||||
@@ -39,37 +44,35 @@ async def _(matcher: Matcher, bot: Bot, event: Event, state: T_State):
|
||||
plugin_list = auto_update_plugin_list(loaded_plugin_list)
|
||||
|
||||
# 无视本插件的 Matcher
|
||||
if plugin not in plugins2info_dict or matcher.priority in [1, 9] or await BanUser.isban(event.user_id):
|
||||
if (
|
||||
plugin not in plugins2info_dict
|
||||
or matcher.priority in [1, 9]
|
||||
or await BanUser.is_ban(event.user_id)
|
||||
):
|
||||
return
|
||||
if isinstance(event, PrivateMessageEvent) and plugin_list[plugin]["default"]:
|
||||
return
|
||||
try:
|
||||
if isinstance(event, PrivateMessageEvent) and plugin_list[plugin]["default"]:
|
||||
return
|
||||
except:
|
||||
pass
|
||||
|
||||
# print(matcher.module)
|
||||
# print(f'plugin_list[plugin]["default"] = {plugin_list[plugin]["default"]}')
|
||||
# print(f'{matcher.module} -> this is hook')
|
||||
if not plugin_list[plugin]["default"]:
|
||||
if event.message_type == 'group':
|
||||
if str(event.user_id) in bot.config.superusers:
|
||||
return
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
if flmt.check(event.group_id):
|
||||
flmt.start_cd(event.group_id)
|
||||
await bot.send_group_msg(group_id=event.group_id, message='此功能正在维护...')
|
||||
await bot.send_group_msg(group_id=event.group_id, message="此功能正在维护...")
|
||||
else:
|
||||
if flmt.check(event.user_id):
|
||||
flmt.start_cd(event.user_id)
|
||||
await bot.send_private_msg(user_id=event.user_id, message='此功能正在维护...')
|
||||
await bot.send_private_msg(user_id=event.user_id, message="此功能正在维护...")
|
||||
raise IgnoredException(f"Nonebot Plugin Manager has blocked {plugin} !")
|
||||
# print(plugin_list[plugin])
|
||||
# print(group_id)
|
||||
# print(plugin_list[plugin][group_id])
|
||||
# print(not plugin_list[plugin][group_id])
|
||||
|
||||
if group_id in plugin_list[plugin]:
|
||||
if not plugin_list[plugin][group_id]:
|
||||
if plugin != 'ai' and matcher.type == 'message':
|
||||
if plugin != "ai" and matcher.type == "message":
|
||||
if flmt.check(event.group_id):
|
||||
flmt.start_cd(event.group_id)
|
||||
await bot.send_group_msg(group_id=event.group_id, message='该群未开启此功能..')
|
||||
await bot.send_group_msg(
|
||||
group_id=event.group_id, message="该群未开启此功能.."
|
||||
)
|
||||
raise IgnoredException(f"Nonebot Plugin Manager has blocked {plugin} !")
|
||||
|
||||
|
||||
@@ -80,7 +83,7 @@ async def _(bot: Bot, event: Event, state: T_State):
|
||||
is_admin = _is_admin(event)
|
||||
is_superuser = _is_superuser(bot, event)
|
||||
if group_id == 0:
|
||||
group_id = 'default'
|
||||
group_id = "default"
|
||||
|
||||
if hasattr(args, "handle"):
|
||||
await plugin_manager.finish(args.handle(args, group_id, is_admin, is_superuser))
|
||||
@@ -116,6 +119,4 @@ def _is_superuser(bot: Bot, event: Event) -> bool:
|
||||
return str(event.user_id) in bot.config.superusers
|
||||
|
||||
|
||||
plugins_dict = {
|
||||
|
||||
}
|
||||
plugins_dict = {}
|
||||
|
||||
Reference in New Issue
Block a user