mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
✨ 增强权限检查,更新请求管理命令和数据库配置逻辑 (#2011)
This commit is contained in:
parent
5c96761fd0
commit
67a2560de4
@ -113,6 +113,11 @@ async def _(
|
|||||||
):
|
):
|
||||||
_is_superuser = is_superuser.result if is_superuser.available else False
|
_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:
|
if name.available:
|
||||||
traditional_help_result = await get_plugin_help(
|
traditional_help_result = await get_plugin_help(
|
||||||
session.user.id, name.result, _is_superuser
|
session.user.id, name.result, _is_superuser
|
||||||
|
|||||||
@ -17,7 +17,7 @@ from nonebot_plugin_alconna import (
|
|||||||
store_true,
|
store_true,
|
||||||
)
|
)
|
||||||
from nonebot_plugin_alconna.uniseg.tools import reply_fetch
|
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.config import BotConfig
|
||||||
from zhenxun.configs.path_config import IMAGE_PATH
|
from zhenxun.configs.path_config import IMAGE_PATH
|
||||||
@ -33,12 +33,14 @@ from zhenxun.utils.utils import get_user_avatar
|
|||||||
usage = """
|
usage = """
|
||||||
查看请求
|
查看请求
|
||||||
清空请求
|
清空请求
|
||||||
请求处理 -fa [id] / 同意好友请求 [id] # 同意好友请求
|
同意请求 [id]
|
||||||
请求处理 -fr [id] / 拒绝好友请求 [id] # 拒绝好友请求
|
拒绝请求 [id]
|
||||||
请求处理 -fi [id] / 忽略好友请求 [id] # 忽略好友请求
|
忽略请求 [id]
|
||||||
请求处理 -ga [id] / 同意群组请求 [id] # 同意群聊请求
|
|
||||||
请求处理 -gr [id] / 拒绝群组请求 [id] # 拒绝群聊请求
|
特别的,在引用消息时,可以不指定id
|
||||||
请求处理 -gi [id] / 忽略群组请求 [id] # 忽略群聊请求
|
/引用消息 同意请求
|
||||||
|
/引用消息 拒绝请求
|
||||||
|
/引用消息 忽略请求
|
||||||
""".strip()
|
""".strip()
|
||||||
|
|
||||||
|
|
||||||
@ -57,11 +59,11 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
_req_matcher = on_alconna(
|
_req_matcher = on_alconna(
|
||||||
Alconna(
|
Alconna(
|
||||||
"请求处理",
|
"请求处理",
|
||||||
Args["handle", ["-fa", "-fr", "-fi", "-ga", "-gr", "-gi"]]["id?", int],
|
Args["handle", ["a", "r", "i"]]["id?", int],
|
||||||
meta=CommandMeta(
|
meta=CommandMeta(
|
||||||
description="好友/群组请求处理",
|
description="请求处理",
|
||||||
usage=usage,
|
usage=usage,
|
||||||
example="同意好友请求 20",
|
example="同意请求 20",
|
||||||
compact=True,
|
compact=True,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -108,12 +110,9 @@ _clear_matcher = on_alconna(
|
|||||||
)
|
)
|
||||||
|
|
||||||
reg_arg_list = [
|
reg_arg_list = [
|
||||||
(r"同意好友请求\s*(?P<id>\d*)", ["-fa", "{id}"]),
|
(r"同意请求\s*(?P<id>\d*)", ["a", "{id}"]),
|
||||||
(r"拒绝好友请求\s*(?P<id>\d*)", ["-fr", "{id}"]),
|
(r"拒绝请求\s*(?P<id>\d*)", ["r", "{id}"]),
|
||||||
(r"忽略好友请求\s*(?P<id>\d*)", ["-fi", "{id}"]),
|
(r"忽略请求\s*(?P<id>\d*)", ["i", "{id}"]),
|
||||||
(r"同意群组请求\s*(?P<id>\d*)", ["-ga", "{id}"]),
|
|
||||||
(r"拒绝群组请求\s*(?P<id>\d*)", ["-gr", "{id}"]),
|
|
||||||
(r"忽略群组请求\s*(?P<id>\d*)", ["-gi", "{id}"]),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
for r in reg_arg_list:
|
for r in reg_arg_list:
|
||||||
@ -129,7 +128,7 @@ for r in reg_arg_list:
|
|||||||
async def _(
|
async def _(
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
event: Event,
|
event: Event,
|
||||||
session: EventSession,
|
session: Uninfo,
|
||||||
handle: str,
|
handle: str,
|
||||||
id: Match[int],
|
id: Match[int],
|
||||||
arparma: Arparma,
|
arparma: Arparma,
|
||||||
@ -153,7 +152,7 @@ async def _(
|
|||||||
).finish(reply_to=True)
|
).finish(reply_to=True)
|
||||||
handle_id = db_data.id
|
handle_id = db_data.id
|
||||||
req = None
|
req = None
|
||||||
handle_type = type_dict[handle[-1]]
|
handle_type = type_dict[handle]
|
||||||
try:
|
try:
|
||||||
if handle_type == RequestHandleType.APPROVE:
|
if handle_type == RequestHandleType.APPROVE:
|
||||||
req = await FgRequest.approve(bot, handle_id)
|
req = await FgRequest.approve(bot, handle_id)
|
||||||
@ -187,7 +186,7 @@ async def _(
|
|||||||
|
|
||||||
@_read_matcher.handle()
|
@_read_matcher.handle()
|
||||||
async def _(
|
async def _(
|
||||||
session: EventSession,
|
session: Uninfo,
|
||||||
arparma: Arparma,
|
arparma: Arparma,
|
||||||
is_friend: Query[bool] = AlconnaQuery("friend.value", False),
|
is_friend: Query[bool] = AlconnaQuery("friend.value", False),
|
||||||
is_group: Query[bool] = AlconnaQuery("group.value", False),
|
is_group: Query[bool] = AlconnaQuery("group.value", False),
|
||||||
@ -283,7 +282,7 @@ async def _(
|
|||||||
|
|
||||||
@_clear_matcher.handle()
|
@_clear_matcher.handle()
|
||||||
async def _(
|
async def _(
|
||||||
session: EventSession,
|
session: Uninfo,
|
||||||
arparma: Arparma,
|
arparma: Arparma,
|
||||||
is_friend: Query[bool] = AlconnaQuery("friend.value", False),
|
is_friend: Query[bool] = AlconnaQuery("friend.value", False),
|
||||||
is_group: Query[bool] = AlconnaQuery("group.value", False),
|
is_group: Query[bool] = AlconnaQuery("group.value", False),
|
||||||
|
|||||||
@ -128,12 +128,14 @@ class FgRequest(Model):
|
|||||||
await bot.set_friend_add_request(
|
await bot.set_friend_add_request(
|
||||||
flag=req.flag, approve=handle_type == RequestHandleType.APPROVE
|
flag=req.flag, approve=handle_type == RequestHandleType.APPROVE
|
||||||
)
|
)
|
||||||
if BotProfileManager.is_auto_send_profile():
|
if (
|
||||||
file_path = await BotProfileManager.build_bot_profile_image(
|
handle_type == RequestHandleType.APPROVE
|
||||||
|
and BotProfileManager.is_auto_send_profile()
|
||||||
|
):
|
||||||
|
if file_path := await BotProfileManager.build_bot_profile_image(
|
||||||
bot.self_id
|
bot.self_id
|
||||||
)
|
):
|
||||||
if file_path:
|
await asyncio.sleep(1)
|
||||||
await asyncio.sleep(2)
|
|
||||||
await PlatformUtils.send_message(
|
await PlatformUtils.send_message(
|
||||||
bot,
|
bot,
|
||||||
req.user_id,
|
req.user_id,
|
||||||
|
|||||||
@ -46,6 +46,8 @@ driver = nonebot.get_driver()
|
|||||||
|
|
||||||
def get_config() -> dict:
|
def get_config() -> dict:
|
||||||
"""获取数据库配置"""
|
"""获取数据库配置"""
|
||||||
|
if not BotConfig.db_url:
|
||||||
|
raise DbUrlIsNode("数据库Url连接字符串为空,请检查配置文件(.env.dev)")
|
||||||
parsed = urlparse(BotConfig.db_url)
|
parsed = urlparse(BotConfig.db_url)
|
||||||
|
|
||||||
# 基础配置
|
# 基础配置
|
||||||
@ -92,7 +94,7 @@ def get_config() -> dict:
|
|||||||
config["connections"]["default"] = {
|
config["connections"]["default"] = {
|
||||||
"engine": "tortoise.backends.sqlite",
|
"engine": "tortoise.backends.sqlite",
|
||||||
"credentials": {
|
"credentials": {
|
||||||
"file_path": parsed.path or ":memory:",
|
"file_path": parsed.path,
|
||||||
},
|
},
|
||||||
**SQLITE_CONFIG,
|
**SQLITE_CONFIG,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,6 @@ from zhenxun.utils.http_utils import AsyncHttpx
|
|||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ARCHIVE_URL_FORMAT,
|
ARCHIVE_URL_FORMAT,
|
||||||
GITEE_RAW_CONTENT_FORMAT,
|
|
||||||
RAW_CONTENT_FORMAT,
|
RAW_CONTENT_FORMAT,
|
||||||
RELEASE_ASSETS_FORMAT,
|
RELEASE_ASSETS_FORMAT,
|
||||||
RELEASE_SOURCE_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]:
|
async def get_fastest_raw_formats() -> list[str]:
|
||||||
"""获取最快的raw下载地址格式"""
|
"""获取最快的raw下载地址格式"""
|
||||||
formats: dict[str, str] = {
|
formats: dict[str, str] = {
|
||||||
"https://gitee.com/": GITEE_RAW_CONTENT_FORMAT,
|
|
||||||
"https://raw.githubusercontent.com/": RAW_CONTENT_FORMAT,
|
"https://raw.githubusercontent.com/": RAW_CONTENT_FORMAT,
|
||||||
"https://ghproxy.cc/": f"https://ghproxy.cc/{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}",
|
"https://gh-proxy.com/": f"https://gh-proxy.com/{RAW_CONTENT_FORMAT}",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user