增强权限检查,更新请求管理命令和数据库配置逻辑 (#2011)

This commit is contained in:
HibiKier 2025-08-06 09:02:07 +08:00 committed by GitHub
parent 5c96761fd0
commit 67a2560de4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 28 deletions

View File

@ -113,6 +113,11 @@ async def _(
):
_is_superuser = is_superuser.result if is_superuser.available else False
if _is_superuser and session.user.id not in bot.config.superusers:
await MessageUtils.build_message("权限不足,无法查看超级用户帮助").finish(
reply_to=True
)
if name.available:
traditional_help_result = await get_plugin_help(
session.user.id, name.result, _is_superuser

View File

@ -17,7 +17,7 @@ from nonebot_plugin_alconna import (
store_true,
)
from nonebot_plugin_alconna.uniseg.tools import reply_fetch
from nonebot_plugin_session import EventSession
from nonebot_plugin_uninfo import Uninfo
from zhenxun.configs.config import BotConfig
from zhenxun.configs.path_config import IMAGE_PATH
@ -33,12 +33,14 @@ from zhenxun.utils.utils import get_user_avatar
usage = """
查看请求
清空请求
请求处理 -fa [id] / 同意好友请求 [id] # 同意好友请求
请求处理 -fr [id] / 拒绝好友请求 [id] # 拒绝好友请求
请求处理 -fi [id] / 忽略好友请求 [id] # 忽略好友请求
请求处理 -ga [id] / 同意群组请求 [id] # 同意群聊请求
请求处理 -gr [id] / 拒绝群组请求 [id] # 拒绝群聊请求
请求处理 -gi [id] / 忽略群组请求 [id] # 忽略群聊请求
同意请求 [id]
拒绝请求 [id]
忽略请求 [id]
特别的在引用消息时可以不指定id
/引用消息 同意请求
/引用消息 拒绝请求
/引用消息 忽略请求
""".strip()
@ -57,11 +59,11 @@ __plugin_meta__ = PluginMetadata(
_req_matcher = on_alconna(
Alconna(
"请求处理",
Args["handle", ["-fa", "-fr", "-fi", "-ga", "-gr", "-gi"]]["id?", int],
Args["handle", ["a", "r", "i"]]["id?", int],
meta=CommandMeta(
description="好友/群组请求处理",
description="请求处理",
usage=usage,
example="同意好友请求 20",
example="同意请求 20",
compact=True,
),
),
@ -108,12 +110,9 @@ _clear_matcher = on_alconna(
)
reg_arg_list = [
(r"同意好友请求\s*(?P<id>\d*)", ["-fa", "{id}"]),
(r"拒绝好友请求\s*(?P<id>\d*)", ["-fr", "{id}"]),
(r"忽略好友请求\s*(?P<id>\d*)", ["-fi", "{id}"]),
(r"同意群组请求\s*(?P<id>\d*)", ["-ga", "{id}"]),
(r"拒绝群组请求\s*(?P<id>\d*)", ["-gr", "{id}"]),
(r"忽略群组请求\s*(?P<id>\d*)", ["-gi", "{id}"]),
(r"同意请求\s*(?P<id>\d*)", ["a", "{id}"]),
(r"拒绝请求\s*(?P<id>\d*)", ["r", "{id}"]),
(r"忽略请求\s*(?P<id>\d*)", ["i", "{id}"]),
]
for r in reg_arg_list:
@ -129,7 +128,7 @@ for r in reg_arg_list:
async def _(
bot: Bot,
event: Event,
session: EventSession,
session: Uninfo,
handle: str,
id: Match[int],
arparma: Arparma,
@ -153,7 +152,7 @@ async def _(
).finish(reply_to=True)
handle_id = db_data.id
req = None
handle_type = type_dict[handle[-1]]
handle_type = type_dict[handle]
try:
if handle_type == RequestHandleType.APPROVE:
req = await FgRequest.approve(bot, handle_id)
@ -187,7 +186,7 @@ async def _(
@_read_matcher.handle()
async def _(
session: EventSession,
session: Uninfo,
arparma: Arparma,
is_friend: Query[bool] = AlconnaQuery("friend.value", False),
is_group: Query[bool] = AlconnaQuery("group.value", False),
@ -283,7 +282,7 @@ async def _(
@_clear_matcher.handle()
async def _(
session: EventSession,
session: Uninfo,
arparma: Arparma,
is_friend: Query[bool] = AlconnaQuery("friend.value", False),
is_group: Query[bool] = AlconnaQuery("group.value", False),

View File

@ -128,12 +128,14 @@ class FgRequest(Model):
await bot.set_friend_add_request(
flag=req.flag, approve=handle_type == RequestHandleType.APPROVE
)
if BotProfileManager.is_auto_send_profile():
file_path = await BotProfileManager.build_bot_profile_image(
if (
handle_type == RequestHandleType.APPROVE
and BotProfileManager.is_auto_send_profile()
):
if file_path := await BotProfileManager.build_bot_profile_image(
bot.self_id
)
if file_path:
await asyncio.sleep(2)
):
await asyncio.sleep(1)
await PlatformUtils.send_message(
bot,
req.user_id,

View File

@ -46,6 +46,8 @@ driver = nonebot.get_driver()
def get_config() -> dict:
"""获取数据库配置"""
if not BotConfig.db_url:
raise DbUrlIsNode("数据库Url连接字符串为空请检查配置文件.env.dev")
parsed = urlparse(BotConfig.db_url)
# 基础配置
@ -92,7 +94,7 @@ def get_config() -> dict:
config["connections"]["default"] = {
"engine": "tortoise.backends.sqlite",
"credentials": {
"file_path": parsed.path or ":memory:",
"file_path": parsed.path,
},
**SQLITE_CONFIG,
}

View File

@ -4,7 +4,6 @@ from zhenxun.utils.http_utils import AsyncHttpx
from .const import (
ARCHIVE_URL_FORMAT,
GITEE_RAW_CONTENT_FORMAT,
RAW_CONTENT_FORMAT,
RELEASE_ASSETS_FORMAT,
RELEASE_SOURCE_FORMAT,
@ -22,7 +21,6 @@ async def __get_fastest_formats(formats: dict[str, str]) -> list[str]:
async def get_fastest_raw_formats() -> list[str]:
"""获取最快的raw下载地址格式"""
formats: dict[str, str] = {
"https://gitee.com/": GITEE_RAW_CONTENT_FORMAT,
"https://raw.githubusercontent.com/": RAW_CONTENT_FORMAT,
"https://ghproxy.cc/": f"https://ghproxy.cc/{RAW_CONTENT_FORMAT}",
"https://gh-proxy.com/": f"https://gh-proxy.com/{RAW_CONTENT_FORMAT}",