mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 12:50:03 +08:00
bugfix:修复插件商店插件卸载问题,显示问题,移除权限检查多余部分 (#2124)
* bugfix:修复插件商店插件卸载问题,显示问题,移除权限检查多余部分 * bugfix:修复撤回问题,插件商店显示问题
This commit is contained in:
@@ -11,7 +11,6 @@ from zhenxun.utils.utils import get_entity_ids
|
||||
|
||||
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
|
||||
from .exception import SkipPluginException
|
||||
from .utils import send_message
|
||||
|
||||
|
||||
async def auth_admin(
|
||||
@@ -51,29 +50,24 @@ async def auth_admin(
|
||||
user_level = max(user_level, group_users.user_level)
|
||||
|
||||
if user_level < plugin.admin_level:
|
||||
await send_message(
|
||||
session,
|
||||
[
|
||||
raise SkipPluginException(
|
||||
f"{plugin.name}({plugin.module}) 管理员权限不足...",
|
||||
tip_message=[
|
||||
At(flag="user", target=session.user.id),
|
||||
f"你的权限不足喔,该功能需要的权限等级: {plugin.admin_level}",
|
||||
],
|
||||
entity.user_id,
|
||||
background=True,
|
||||
)
|
||||
|
||||
raise SkipPluginException(
|
||||
f"{plugin.name}({plugin.module}) 管理员权限不足..."
|
||||
tip_check_tag=entity.user_id,
|
||||
tip_background=True,
|
||||
)
|
||||
elif global_user:
|
||||
if global_user.user_level < plugin.admin_level:
|
||||
await send_message(
|
||||
session,
|
||||
f"你的权限不足喔,该功能需要的权限等级: {plugin.admin_level}",
|
||||
background=True,
|
||||
)
|
||||
|
||||
raise SkipPluginException(
|
||||
f"{plugin.name}({plugin.module}) 管理员权限不足..."
|
||||
f"{plugin.name}({plugin.module}) 管理员权限不足...",
|
||||
tip_message=(
|
||||
f"你的权限不足喔,该功能需要的权限等级: "
|
||||
f"{plugin.admin_level}"
|
||||
),
|
||||
tip_background=True,
|
||||
)
|
||||
finally:
|
||||
# 记录执行时间
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot_plugin_alconna import At
|
||||
from nonebot_plugin_uninfo import Uninfo
|
||||
@@ -18,7 +17,7 @@ from zhenxun.utils.utils import EntityIDs, get_entity_ids
|
||||
|
||||
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
|
||||
from .exception import SkipPluginException
|
||||
from .utils import freq, send_message
|
||||
from .utils import freq
|
||||
|
||||
Config.add_plugin_config(
|
||||
"hook",
|
||||
@@ -189,20 +188,15 @@ async def user_handle(plugin: PluginInfo, entity: EntityIDs, session: Uninfo) ->
|
||||
and ban_result
|
||||
and freq.is_send_limit_message(plugin, entity.user_id, False)
|
||||
):
|
||||
try:
|
||||
await asyncio.wait_for(
|
||||
send_message(
|
||||
session,
|
||||
[
|
||||
At(flag="user", target=entity.user_id),
|
||||
f"{ban_result}\n在..在 {time_str} 后才会理你喔",
|
||||
],
|
||||
entity.user_id,
|
||||
),
|
||||
timeout=DB_TIMEOUT_SECONDS,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
logger.error(f"发送消息超时: {entity.user_id}", LOGGER_COMMAND)
|
||||
raise SkipPluginException(
|
||||
"用户处于黑名单中...",
|
||||
tip_message=[
|
||||
At(flag="user", target=entity.user_id),
|
||||
f"{ban_result}\n在..在 {time_str} 后才会理你喔",
|
||||
],
|
||||
tip_check_tag=entity.user_id,
|
||||
tip_timeout=DB_TIMEOUT_SECONDS,
|
||||
)
|
||||
raise SkipPluginException("用户处于黑名单中...")
|
||||
finally:
|
||||
# 记录执行时间
|
||||
@@ -217,16 +211,16 @@ async def user_handle(plugin: PluginInfo, entity: EntityIDs, session: Uninfo) ->
|
||||
|
||||
async def auth_ban(
|
||||
matcher: Matcher,
|
||||
bot: Bot,
|
||||
session: Uninfo,
|
||||
plugin: PluginInfo,
|
||||
*,
|
||||
entity: EntityIDs | None = None,
|
||||
is_superuser: bool = False,
|
||||
) -> None:
|
||||
"""权限检查 - ban 检查
|
||||
|
||||
参数:
|
||||
matcher: Matcher
|
||||
bot: Bot
|
||||
session: Uninfo
|
||||
"""
|
||||
start_time = time.time()
|
||||
@@ -237,7 +231,7 @@ async def auth_ban(
|
||||
return
|
||||
if entity is None:
|
||||
entity = get_entity_ids(session)
|
||||
if entity.user_id in bot.config.superusers:
|
||||
if is_superuser:
|
||||
return
|
||||
if entity.group_id:
|
||||
try:
|
||||
|
||||
@@ -8,7 +8,6 @@ from zhenxun.services.log import logger
|
||||
|
||||
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
|
||||
from .exception import SkipPluginException
|
||||
from .utils import send_message
|
||||
|
||||
DEFAULT_GOLD = 100
|
||||
|
||||
@@ -32,8 +31,10 @@ async def auth_cost(
|
||||
user_gold = user.gold if user else DEFAULT_GOLD
|
||||
if user_gold < plugin.cost_gold:
|
||||
"""插件消耗金币不足"""
|
||||
await send_message(session, f"金币不足..该功能需要{plugin.cost_gold}金币..")
|
||||
raise SkipPluginException(f"{plugin.name}({plugin.module}) 金币限制...")
|
||||
raise SkipPluginException(
|
||||
f"{plugin.name}({plugin.module}) 金币限制...",
|
||||
tip_message=f"金币不足..该功能需要{plugin.cost_gold}金币..",
|
||||
)
|
||||
return plugin.cost_gold
|
||||
finally:
|
||||
# 记录执行时间
|
||||
|
||||
@@ -11,7 +11,7 @@ from zhenxun.utils.enum import BlockType
|
||||
|
||||
from .config import LOGGER_COMMAND, WARNING_THRESHOLD
|
||||
from .exception import IsSuperuserException, SkipPluginException
|
||||
from .utils import freq, is_poke, send_message
|
||||
from .utils import freq, is_poke
|
||||
|
||||
|
||||
def _get_group_block_sets(
|
||||
@@ -59,46 +59,41 @@ class GroupCheck:
|
||||
self.group_data
|
||||
and self.plugin.module in self.superuser_block_plugin_set
|
||||
):
|
||||
if freq.is_send_limit_message(
|
||||
should_tip = freq.is_send_limit_message(
|
||||
self.plugin, self.group_id, self.is_poke
|
||||
):
|
||||
await send_message(
|
||||
self.session,
|
||||
"超级管理员禁用了该群此功能...",
|
||||
self.group_id,
|
||||
background=True,
|
||||
)
|
||||
)
|
||||
raise SkipPluginException(
|
||||
f"{self.plugin.name}({self.plugin.module})"
|
||||
f" 超级管理员禁用了该群此功能..."
|
||||
f" 超级管理员禁用了该群此功能...",
|
||||
tip_message=(
|
||||
"超级管理员禁用了该群此功能..." if should_tip else None
|
||||
),
|
||||
tip_check_tag=self.group_id if should_tip else None,
|
||||
tip_background=should_tip,
|
||||
)
|
||||
|
||||
# 检查普通禁用
|
||||
if self.group_data and self.plugin.module in self.block_plugin_set:
|
||||
if freq.is_send_limit_message(
|
||||
should_tip = freq.is_send_limit_message(
|
||||
self.plugin, self.group_id, self.is_poke
|
||||
):
|
||||
await send_message(
|
||||
self.session,
|
||||
"该群未开启此功能...",
|
||||
self.group_id,
|
||||
background=True,
|
||||
)
|
||||
)
|
||||
raise SkipPluginException(
|
||||
f"{self.plugin.name}({self.plugin.module}) 未开启此功能..."
|
||||
f"{self.plugin.name}({self.plugin.module}) 未开启此功能...",
|
||||
tip_message="该群未开启此功能..." if should_tip else None,
|
||||
tip_check_tag=self.group_id if should_tip else None,
|
||||
tip_background=should_tip,
|
||||
)
|
||||
|
||||
# 检查全局禁用
|
||||
if self.plugin.block_type == BlockType.GROUP:
|
||||
if freq.is_send_limit_message(self.plugin, self.group_id, self.is_poke):
|
||||
await send_message(
|
||||
self.session,
|
||||
"该功能在群组中已被禁用...",
|
||||
self.group_id,
|
||||
background=True,
|
||||
)
|
||||
should_tip = freq.is_send_limit_message(
|
||||
self.plugin, self.group_id, self.is_poke
|
||||
)
|
||||
raise SkipPluginException(
|
||||
f"{self.plugin.name}({self.plugin.module})该插件在群组中已被禁用..."
|
||||
f"{self.plugin.name}({self.plugin.module})该插件在群组中已被禁用...",
|
||||
tip_message="该功能在群组中已被禁用..." if should_tip else None,
|
||||
tip_check_tag=self.group_id if should_tip else None,
|
||||
tip_background=should_tip,
|
||||
)
|
||||
finally:
|
||||
# 记录执行时间
|
||||
@@ -131,14 +126,14 @@ class PluginCheck:
|
||||
IgnoredException: 忽略插件
|
||||
"""
|
||||
if plugin.block_type == BlockType.PRIVATE:
|
||||
if freq.is_send_limit_message(plugin, self.session.user.id, self.is_poke):
|
||||
await send_message(
|
||||
self.session,
|
||||
"该功能在私聊中已被禁用...",
|
||||
background=True,
|
||||
)
|
||||
should_tip = freq.is_send_limit_message(
|
||||
plugin, self.session.user.id, self.is_poke
|
||||
)
|
||||
raise SkipPluginException(
|
||||
f"{plugin.name}({plugin.module}) 该插件在私聊中已被禁用..."
|
||||
f"{plugin.name}({plugin.module}) 该插件在私聊中已被禁用...",
|
||||
tip_message="该功能在私聊中已被禁用..." if should_tip else None,
|
||||
tip_check_tag=self.session.user.id if should_tip else None,
|
||||
tip_background=should_tip,
|
||||
)
|
||||
|
||||
async def check_global(self, plugin: PluginInfo):
|
||||
@@ -159,15 +154,12 @@ class PluginCheck:
|
||||
raise IsSuperuserException()
|
||||
|
||||
sid = self.group_id or self.session.user.id
|
||||
if freq.is_send_limit_message(plugin, sid, self.is_poke):
|
||||
await send_message(
|
||||
self.session,
|
||||
"全局未开启此功能...",
|
||||
sid,
|
||||
background=True,
|
||||
)
|
||||
should_tip = freq.is_send_limit_message(plugin, sid, self.is_poke)
|
||||
raise SkipPluginException(
|
||||
f"{plugin.name}({plugin.module}) 全局未开启此功能..."
|
||||
f"{plugin.name}({plugin.module}) 全局未开启此功能...",
|
||||
tip_message="全局未开启此功能..." if should_tip else None,
|
||||
tip_check_tag=sid if should_tip else None,
|
||||
tip_background=should_tip,
|
||||
)
|
||||
finally:
|
||||
# 记录执行时间
|
||||
|
||||
@@ -3,9 +3,21 @@ class IsSuperuserException(Exception):
|
||||
|
||||
|
||||
class SkipPluginException(Exception):
|
||||
def __init__(self, info: str, *args: object) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
info: str,
|
||||
*args: object,
|
||||
tip_message: list | str | None = None,
|
||||
tip_check_tag: str | None = None,
|
||||
tip_background: bool = False,
|
||||
tip_timeout: float | None = None,
|
||||
) -> None:
|
||||
super().__init__(*args)
|
||||
self.info = info
|
||||
self.tip_message = tip_message
|
||||
self.tip_check_tag = tip_check_tag
|
||||
self.tip_background = tip_background
|
||||
self.tip_timeout = tip_timeout
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.info
|
||||
|
||||
Reference in New Issue
Block a user