mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-18 18:50:05 +08:00
⚡️ 优化权限判断
This commit is contained in:
@@ -220,7 +220,9 @@ async def _(
|
||||
await MessageUtils.build_message("权限不足捏...").finish(reply_to=True)
|
||||
user_id = user.result
|
||||
if gid := session.id3 or session.id2:
|
||||
u_d = user_id
|
||||
if group_id.available:
|
||||
u_d = gid
|
||||
gid = group_id.result
|
||||
if await BanManage.unban(
|
||||
user_id, gid, session, session.id1 in bot.config.superusers
|
||||
@@ -234,7 +236,7 @@ async def _(
|
||||
await MessageUtils.build_message(
|
||||
[
|
||||
"将 ",
|
||||
At(flag="user", target=user_id) if isinstance(user.result, At) else user_id, # type: ignore
|
||||
At(flag="user", target=user_id) if isinstance(user.result, At) else u_d, # type: ignore
|
||||
f" 从黑屋中拉了出来并急救了一下!",
|
||||
]
|
||||
).finish(reply_to=True)
|
||||
|
||||
@@ -30,7 +30,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
extra=PluginExtraData(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.HIDDEN,
|
||||
plugin_type=PluginType.DEPENDANT,
|
||||
configs=[
|
||||
RegisterConfig(
|
||||
key="type",
|
||||
|
||||
@@ -49,7 +49,7 @@ class HelpImageBuild:
|
||||
self._data = await PluginInfo.filter(
|
||||
menu_type__not="",
|
||||
load_status=True,
|
||||
plugin_type__in=[PluginType.NORMAL, PluginType.HIDDEN],
|
||||
plugin_type__in=[PluginType.NORMAL, PluginType.DEPENDANT],
|
||||
)
|
||||
if not self._sort_data:
|
||||
for plugin in self._data:
|
||||
|
||||
@@ -24,7 +24,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
extra=PluginExtraData(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.HIDDEN,
|
||||
plugin_type=PluginType.DEPENDANT,
|
||||
).dict(),
|
||||
)
|
||||
|
||||
|
||||
@@ -40,4 +40,13 @@ Config.add_plugin_config(
|
||||
type=int,
|
||||
)
|
||||
|
||||
Config.add_plugin_config(
|
||||
"hook",
|
||||
"IS_SEND_TIP_MESSAGE",
|
||||
True,
|
||||
help="是否发送阻断时提示消息",
|
||||
default_value=True,
|
||||
type=bool,
|
||||
)
|
||||
|
||||
nonebot.load_plugins(str(Path(__file__).parent.resolve()))
|
||||
|
||||
@@ -25,6 +25,8 @@ from zhenxun.utils.exception import InsufficientGold
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.utils import CountLimiter, FreqLimiter, UserBlockLimiter
|
||||
|
||||
base_config = Config.get("hook")
|
||||
|
||||
|
||||
class Limit(BaseModel):
|
||||
|
||||
@@ -181,6 +183,23 @@ class AuthChecker:
|
||||
self._flmt_s = FreqLimiter(check_notice_info_cd)
|
||||
self._flmt_c = FreqLimiter(check_notice_info_cd)
|
||||
|
||||
def is_send_limit_message(self, plugin: PluginInfo, sid: str) -> bool:
|
||||
"""是否发送提示消息
|
||||
|
||||
参数:
|
||||
plugin: PluginInfo
|
||||
|
||||
返回:
|
||||
bool: 是否发送提示消息
|
||||
"""
|
||||
if not base_config.get("IS_SEND_TIP_MESSAGE"):
|
||||
return False
|
||||
if plugin.plugin_type == PluginType.DEPENDANT:
|
||||
return False
|
||||
if not self._flmt_s.check(sid):
|
||||
return False
|
||||
return True
|
||||
|
||||
async def auth(
|
||||
self,
|
||||
matcher: Matcher,
|
||||
@@ -217,8 +236,8 @@ class AuthChecker:
|
||||
)
|
||||
return
|
||||
if plugin := await PluginInfo.get_or_none(module_path=module_path):
|
||||
if plugin.plugin_type == PluginType.HIDDEN and plugin.name != "帮助":
|
||||
logger.debug("插件为HIDDEN且不是帮助功能,已跳过...")
|
||||
if plugin.plugin_type == PluginType.HIDDEN:
|
||||
logger.debug("插件为HIDDEN,已跳过...")
|
||||
return
|
||||
try:
|
||||
cost_gold = await self.auth_cost(user, plugin, session)
|
||||
@@ -301,11 +320,12 @@ class AuthChecker:
|
||||
channel_id = None
|
||||
if user_id:
|
||||
if group_id:
|
||||
sid = group_id or user_id
|
||||
if await GroupConsole.is_super_block_plugin(
|
||||
group_id, plugin.module, channel_id
|
||||
):
|
||||
"""超级用户群组插件状态"""
|
||||
if self._flmt_s.check(group_id or user_id) and not is_poke:
|
||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
||||
self._flmt_s.start_cd(group_id or user_id)
|
||||
await MessageUtils.build_message(
|
||||
"超级管理员禁用了该群此功能..."
|
||||
@@ -320,7 +340,7 @@ class AuthChecker:
|
||||
group_id, plugin.module, channel_id
|
||||
):
|
||||
"""群组插件状态"""
|
||||
if self._flmt_s.check(group_id or user_id) and not is_poke:
|
||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
||||
self._flmt_s.start_cd(group_id or user_id)
|
||||
await MessageUtils.build_message("该群未开启此功能...").send(
|
||||
reply_to=True
|
||||
@@ -334,7 +354,7 @@ class AuthChecker:
|
||||
if not plugin.status and plugin.block_type == BlockType.GROUP:
|
||||
"""全局群组禁用"""
|
||||
try:
|
||||
if self._flmt_c.check(group_id) and not is_poke:
|
||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
||||
self._flmt_c.start_cd(group_id)
|
||||
await MessageUtils.build_message(
|
||||
"该功能在群组中已被禁用..."
|
||||
@@ -350,10 +370,11 @@ class AuthChecker:
|
||||
)
|
||||
raise IgnoredException("该插件在群组中已被禁用...")
|
||||
else:
|
||||
sid = user_id
|
||||
if not plugin.status and plugin.block_type == BlockType.PRIVATE:
|
||||
"""全局私聊禁用"""
|
||||
try:
|
||||
if self._flmt_c.check(user_id) and not is_poke:
|
||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
||||
self._flmt_c.start_cd(user_id)
|
||||
await MessageUtils.build_message(
|
||||
"该功能在私聊中已被禁用..."
|
||||
@@ -378,7 +399,7 @@ class AuthChecker:
|
||||
"HOOK",
|
||||
session=session,
|
||||
)
|
||||
if self._flmt_s.check(group_id or user_id) and not is_poke:
|
||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
||||
self._flmt_s.start_cd(group_id or user_id)
|
||||
await MessageUtils.build_message("全局未开启此功能...").send()
|
||||
raise IgnoredException("全局未开启此功能...")
|
||||
|
||||
@@ -69,7 +69,7 @@ async def _(matcher: Matcher, bot: Bot, session: EventSession, state: T_State):
|
||||
module = plugin.module_name
|
||||
if metadata := plugin.metadata:
|
||||
extra = metadata.extra
|
||||
if extra.get("plugin_type") == PluginType.HIDDEN:
|
||||
if extra.get("plugin_type") in [PluginType.HIDDEN, PluginType.DEPENDANT]:
|
||||
return
|
||||
else:
|
||||
return
|
||||
|
||||
@@ -49,8 +49,9 @@ async def _handle_setting(
|
||||
if metadata.type == "library":
|
||||
extra_data.plugin_type = PluginType.HIDDEN
|
||||
if (
|
||||
extra_data.plugin_type == PluginType.HIDDEN
|
||||
and extra_data.plugin_type != "功能"
|
||||
extra_data.plugin_type
|
||||
== PluginType.HIDDEN
|
||||
# and extra_data.plugin_type != "功能"
|
||||
):
|
||||
extra_data.menu_type = ""
|
||||
plugin_list.append(
|
||||
@@ -119,15 +120,26 @@ async def _():
|
||||
create_list.append(plugin)
|
||||
else:
|
||||
plugin.id = module2id[plugin.module_path]
|
||||
await plugin.save(
|
||||
update_fields=[
|
||||
"name",
|
||||
"author",
|
||||
"version",
|
||||
"admin_level",
|
||||
"plugin_type",
|
||||
]
|
||||
)
|
||||
update_list.append(plugin)
|
||||
if create_list:
|
||||
await PluginInfo.bulk_create(create_list, 10)
|
||||
if update_list:
|
||||
await PluginInfo.bulk_update(
|
||||
update_list,
|
||||
["name", "author", "version", "admin_level"],
|
||||
10,
|
||||
)
|
||||
# TODO: 批量更新无法更新plugin_type: tortoise.exceptions.OperationalError: column "superuser" does not exist
|
||||
pass
|
||||
# await PluginInfo.bulk_update(
|
||||
# update_list,
|
||||
# ["name", "author", "version", "admin_level", "plugin_type"],
|
||||
# 10,
|
||||
# )
|
||||
if limit_list:
|
||||
limit_create = []
|
||||
plugins = []
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from asyncio.exceptions import TimeoutError
|
||||
|
||||
import nonebot
|
||||
import ujson as json
|
||||
from nonebot.drivers import Driver
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
|
||||
@@ -8,12 +9,6 @@ from zhenxun.configs.path_config import TEXT_PATH
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
except ModuleNotFoundError:
|
||||
import json
|
||||
|
||||
|
||||
driver: Driver = nonebot.get_driver()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user