mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-08 13:20:01 +08:00
版本更新
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import nonebot
|
||||
from fastapi import APIRouter
|
||||
from tortoise.functions import Count
|
||||
from fastapi.responses import JSONResponse
|
||||
from nonebot.adapters.onebot.v11 import ActionFailed
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
@@ -41,7 +42,11 @@ router = APIRouter(prefix="/manage")
|
||||
|
||||
|
||||
@router.get(
|
||||
"/get_group_list", dependencies=[authentication()], description="获取群组列表"
|
||||
"/get_group_list",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[list[GroupResult]],
|
||||
response_class=JSONResponse,
|
||||
description="获取群组列表",
|
||||
)
|
||||
async def _(bot_id: str) -> Result:
|
||||
"""
|
||||
@@ -65,9 +70,13 @@ async def _(bot_id: str) -> Result:
|
||||
|
||||
|
||||
@router.post(
|
||||
"/update_group", dependencies=[authentication()], description="修改群组信息"
|
||||
"/update_group",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[str],
|
||||
response_class=JSONResponse,
|
||||
description="修改群组信息",
|
||||
)
|
||||
async def _(group: UpdateGroup) -> Result:
|
||||
async def _(group: UpdateGroup) -> Result[str]:
|
||||
try:
|
||||
group_id = group.group_id
|
||||
if db_group := await GroupConsole.get_group(group_id):
|
||||
@@ -75,9 +84,11 @@ async def _(group: UpdateGroup) -> Result:
|
||||
db_group.level = group.level
|
||||
db_group.status = group.status
|
||||
if group.close_plugins:
|
||||
group.close_plugins = [f"<{module}" for module in group.close_plugins]
|
||||
db_group.block_plugin = ",".join(group.close_plugins) + ","
|
||||
if group.task:
|
||||
if block_task := [t for t in task_list if t not in group.task]:
|
||||
block_task = [f"<{module}" for module in block_task]
|
||||
db_group.block_task = ",".join(block_task) + "," # type: ignore
|
||||
await db_group.save(
|
||||
update_fields=["level", "status", "block_plugin", "block_task"]
|
||||
@@ -89,9 +100,13 @@ async def _(group: UpdateGroup) -> Result:
|
||||
|
||||
|
||||
@router.get(
|
||||
"/get_friend_list", dependencies=[authentication()], description="获取好友列表"
|
||||
"/get_friend_list",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[list[Friend]],
|
||||
response_class=JSONResponse,
|
||||
description="获取好友列表",
|
||||
)
|
||||
async def _(bot_id: str) -> Result:
|
||||
async def _(bot_id: str) -> Result[list[Friend]]:
|
||||
"""
|
||||
获取群信息
|
||||
"""
|
||||
@@ -116,9 +131,13 @@ async def _(bot_id: str) -> Result:
|
||||
|
||||
|
||||
@router.get(
|
||||
"/get_request_count", dependencies=[authentication()], description="获取请求数量"
|
||||
"/get_request_count",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[dict[str, int]],
|
||||
response_class=JSONResponse,
|
||||
description="获取请求数量",
|
||||
)
|
||||
async def _() -> Result:
|
||||
async def _() -> Result[dict[str, int]]:
|
||||
f_count = await FgRequest.filter(
|
||||
request_type=RequestType.FRIEND, handle_type__isnull=True
|
||||
).count()
|
||||
@@ -133,9 +152,13 @@ async def _() -> Result:
|
||||
|
||||
|
||||
@router.get(
|
||||
"/get_request_list", dependencies=[authentication()], description="获取请求列表"
|
||||
"/get_request_list",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[ReqResult],
|
||||
response_class=JSONResponse,
|
||||
description="获取请求列表",
|
||||
)
|
||||
async def _() -> Result:
|
||||
async def _() -> Result[ReqResult]:
|
||||
try:
|
||||
req_result = ReqResult()
|
||||
data_list = await FgRequest.filter(handle_type__isnull=True).all()
|
||||
@@ -177,7 +200,11 @@ async def _() -> Result:
|
||||
|
||||
|
||||
@router.post(
|
||||
"/clear_request", dependencies=[authentication()], description="清空请求列表"
|
||||
"/clear_request",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result,
|
||||
response_class=JSONResponse,
|
||||
description="清空请求列表",
|
||||
)
|
||||
async def _(cr: ClearRequest) -> Result:
|
||||
await FgRequest.filter(
|
||||
@@ -186,7 +213,13 @@ async def _(cr: ClearRequest) -> Result:
|
||||
return Result.ok(info="成功清除了数据!")
|
||||
|
||||
|
||||
@router.post("/refuse_request", dependencies=[authentication()], description="拒绝请求")
|
||||
@router.post(
|
||||
"/refuse_request",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result,
|
||||
response_class=JSONResponse,
|
||||
description="拒绝请求",
|
||||
)
|
||||
async def _(parma: HandleRequest) -> Result:
|
||||
try:
|
||||
if bots := nonebot.get_bots():
|
||||
@@ -207,14 +240,24 @@ async def _(parma: HandleRequest) -> Result:
|
||||
return Result.fail(f"{type(e)}: {e}")
|
||||
|
||||
|
||||
@router.post("/delete_request", dependencies=[authentication()], description="忽略请求")
|
||||
@router.post(
|
||||
"/delete_request",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result,
|
||||
response_class=JSONResponse,
|
||||
description="忽略请求",
|
||||
)
|
||||
async def _(parma: HandleRequest) -> Result:
|
||||
await FgRequest.ignore(parma.id)
|
||||
return Result.ok(info="成功处理了请求!")
|
||||
|
||||
|
||||
@router.post(
|
||||
"/approve_request", dependencies=[authentication()], description="同意请求"
|
||||
"/approve_request",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result,
|
||||
response_class=JSONResponse,
|
||||
description="同意请求",
|
||||
)
|
||||
async def _(parma: HandleRequest) -> Result:
|
||||
try:
|
||||
@@ -245,7 +288,13 @@ async def _(parma: HandleRequest) -> Result:
|
||||
return Result.fail(f"{type(e)}: {e}")
|
||||
|
||||
|
||||
@router.post("/leave_group", dependencies=[authentication()], description="退群")
|
||||
@router.post(
|
||||
"/leave_group",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result,
|
||||
response_class=JSONResponse,
|
||||
description="退群",
|
||||
)
|
||||
async def _(param: LeaveGroup) -> Result:
|
||||
try:
|
||||
if bots := nonebot.get_bots():
|
||||
@@ -264,7 +313,13 @@ async def _(param: LeaveGroup) -> Result:
|
||||
return Result.fail(f"{type(e)}: {e}")
|
||||
|
||||
|
||||
@router.post("/delete_friend", dependencies=[authentication()], description="删除好友")
|
||||
@router.post(
|
||||
"/delete_friend",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result,
|
||||
response_class=JSONResponse,
|
||||
description="删除好友",
|
||||
)
|
||||
async def _(param: DeleteFriend) -> Result:
|
||||
try:
|
||||
if bots := nonebot.get_bots():
|
||||
@@ -284,9 +339,13 @@ async def _(param: DeleteFriend) -> Result:
|
||||
|
||||
|
||||
@router.get(
|
||||
"/get_friend_detail", dependencies=[authentication()], description="获取好友详情"
|
||||
"/get_friend_detail",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[UserDetail],
|
||||
response_class=JSONResponse,
|
||||
description="获取好友详情",
|
||||
)
|
||||
async def _(bot_id: str, user_id: str) -> Result:
|
||||
async def _(bot_id: str, user_id: str) -> Result[UserDetail]:
|
||||
if bots := nonebot.get_bots():
|
||||
if bot_id in bots:
|
||||
if fd := [
|
||||
@@ -327,9 +386,13 @@ async def _(bot_id: str, user_id: str) -> Result:
|
||||
|
||||
|
||||
@router.get(
|
||||
"/get_group_detail", dependencies=[authentication()], description="获取群组详情"
|
||||
"/get_group_detail",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result[GroupDetail],
|
||||
response_class=JSONResponse,
|
||||
description="获取群组详情",
|
||||
)
|
||||
async def _(bot_id: str, group_id: str) -> Result:
|
||||
async def _(bot_id: str, group_id: str) -> Result[GroupDetail]:
|
||||
if not (bots := nonebot.get_bots()):
|
||||
return Result.warning_("无Bot连接...")
|
||||
if bot_id not in bots:
|
||||
@@ -346,34 +409,46 @@ async def _(bot_id: str, group_id: str) -> Result:
|
||||
.values_list("plugin_name", "count")
|
||||
)
|
||||
like_plugin = {}
|
||||
plugins = await PluginInfo.all()
|
||||
plugins = await PluginInfo.get_plugins()
|
||||
module2name = {p.module: p.name for p in plugins}
|
||||
for data in like_plugin_list:
|
||||
name = module2name.get(data[0]) or data[0]
|
||||
like_plugin[name] = data[1]
|
||||
close_plugins = []
|
||||
close_plugins: list[Plugin] = []
|
||||
if group.block_plugin:
|
||||
for module in group.block_plugin.split(","):
|
||||
module_ = module.replace(":super", "")
|
||||
is_super_block = module.endswith(":super")
|
||||
plugin = Plugin(
|
||||
module=module_,
|
||||
plugin_name=module,
|
||||
is_super_block=is_super_block,
|
||||
)
|
||||
plugin.plugin_name = module2name.get(module) or module
|
||||
close_plugins.append(plugin)
|
||||
for module in group.block_plugin.replace("<", "").split(","):
|
||||
if module:
|
||||
plugin = Plugin(
|
||||
module=module,
|
||||
plugin_name=module,
|
||||
is_super_block=False,
|
||||
)
|
||||
plugin.plugin_name = module2name.get(module) or module
|
||||
close_plugins.append(plugin)
|
||||
exists_modules = [p.module for p in close_plugins]
|
||||
if group.superuser_block_plugin:
|
||||
for module in group.superuser_block_plugin.replace("<", "").split(","):
|
||||
if module and module not in exists_modules:
|
||||
plugin = Plugin(
|
||||
module=module,
|
||||
plugin_name=module,
|
||||
is_super_block=True,
|
||||
)
|
||||
plugin.plugin_name = module2name.get(module) or module
|
||||
close_plugins.append(plugin)
|
||||
all_task = await TaskInfo.annotate().values_list("module", "name")
|
||||
task_module2name = {x[0]: x[1] for x in all_task}
|
||||
task_list = []
|
||||
if group.block_task:
|
||||
split_task = group.block_task.split(",")
|
||||
if group.block_task or group.superuser_block_plugin:
|
||||
sbp = group.superuser_block_plugin.replace("<", "").split(",")
|
||||
split_task = group.block_task.replace("<", "").split(",")
|
||||
for task in all_task:
|
||||
task_list.append(
|
||||
Task(
|
||||
name=task[0],
|
||||
zh_name=task_module2name.get(task[0]) or task[0],
|
||||
status=task[0] not in split_task,
|
||||
status=task[0] not in split_task and task[0] not in sbp,
|
||||
is_super_block=task[0] in sbp,
|
||||
)
|
||||
)
|
||||
else:
|
||||
@@ -383,6 +458,7 @@ async def _(bot_id: str, group_id: str) -> Result:
|
||||
name=task[0],
|
||||
zh_name=task_module2name.get(task[0]) or task[0],
|
||||
status=True,
|
||||
is_super_block=False,
|
||||
)
|
||||
)
|
||||
group_detail = GroupDetail(
|
||||
@@ -403,7 +479,11 @@ async def _(bot_id: str, group_id: str) -> Result:
|
||||
|
||||
|
||||
@router.post(
|
||||
"/send_message", dependencies=[authentication()], description="获取群组详情"
|
||||
"/send_message",
|
||||
dependencies=[authentication()],
|
||||
response_model=Result,
|
||||
response_class=JSONResponse,
|
||||
description="获取群组详情",
|
||||
)
|
||||
async def _(param: SendMessage) -> Result:
|
||||
if not (bots := nonebot.get_bots()):
|
||||
|
||||
@@ -29,6 +29,8 @@ class Task(BaseModel):
|
||||
"""被动中文名称"""
|
||||
status: bool
|
||||
"""状态"""
|
||||
is_super_block: bool
|
||||
"""是否超级用户禁用"""
|
||||
|
||||
|
||||
class Plugin(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user