mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🐛 修改webui
This commit is contained in:
parent
2251f5fafa
commit
5e4de123b0
@ -50,13 +50,13 @@ router = APIRouter(prefix="/manage")
|
|||||||
|
|
||||||
SUB_PATTERN = r"\x1b(\[.*?[@-~]|\].*?(\x07|\x1b\\))"
|
SUB_PATTERN = r"\x1b(\[.*?[@-~]|\].*?(\x07|\x1b\\))"
|
||||||
|
|
||||||
GROUP_PATTERN = r'.*?Message (-?\d*) from (\d*)@\[群:(\d*)] "(.*)"'
|
GROUP_PATTERN = r".*?Message (-?\d*) from (\d*)@\[群:(\d*)] '(.*)'"
|
||||||
|
|
||||||
PRIVATE_PATTERN = r'.*?Message (-?\d*) from (\d*) "(.*)"'
|
PRIVATE_PATTERN = r".*?Message (-?\d*) from (\d*) '(.*)'"
|
||||||
|
|
||||||
AT_PATTERN = r"\[CQ:at,qq=(.*)\]"
|
AT_PATTERN = r"\[CQ:at,qq=(.*)\]"
|
||||||
|
|
||||||
IMAGE_PATTERN = r"\[CQ:image,.*,url=(.*);.*?\]"
|
IMAGE_PATTERN = r"\[image:file=.*,url=(.*);.*?\]"
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
@ -90,13 +90,22 @@ async def _(bot_id: str) -> Result:
|
|||||||
async def _(group: UpdateGroup) -> Result:
|
async def _(group: UpdateGroup) -> Result:
|
||||||
try:
|
try:
|
||||||
group_id = group.group_id
|
group_id = group.group_id
|
||||||
if db_group := await GroupConsole.get_or_none(group_id=group_id):
|
if db_group := await GroupConsole.get_group(group_id):
|
||||||
|
task_list = await TaskInfo.all().values_list("module", flat=True)
|
||||||
db_group.level = group.level
|
db_group.level = group.level
|
||||||
db_group.status = group.status
|
db_group.status = group.status
|
||||||
if group.close_plugins:
|
if group.close_plugins:
|
||||||
db_group.block_plugin = ",".join(group.close_plugins) + ","
|
db_group.block_plugin = ",".join(group.close_plugins) + ","
|
||||||
# TODO: 关闭task
|
if group.task:
|
||||||
await db_group.save(update_fields=["level", "status", "block_plugin"])
|
block_task = []
|
||||||
|
for t in task_list:
|
||||||
|
if t not in group.task:
|
||||||
|
block_task.append(t)
|
||||||
|
if block_task:
|
||||||
|
db_group.block_task = ",".join(block_task) + ","
|
||||||
|
await db_group.save(
|
||||||
|
update_fields=["level", "status", "block_plugin", "block_task"]
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("调用API错误", "/get_group", e=e)
|
logger.error("调用API错误", "/get_group", e=e)
|
||||||
return Result.fail(f"{type(e)}: {e}")
|
return Result.fail(f"{type(e)}: {e}")
|
||||||
@ -149,7 +158,7 @@ async def _() -> Result:
|
|||||||
async def _() -> Result:
|
async def _() -> Result:
|
||||||
try:
|
try:
|
||||||
req_result = ReqResult()
|
req_result = ReqResult()
|
||||||
data_list = await FgRequest.filter(handle_type__not_isnull=True).all()
|
data_list = await FgRequest.filter(handle_type__isnull=True).all()
|
||||||
for req in data_list:
|
for req in data_list:
|
||||||
if req.request_type == RequestType.FRIEND:
|
if req.request_type == RequestType.FRIEND:
|
||||||
req_result.friend.append(
|
req_result.friend.append(
|
||||||
@ -220,7 +229,7 @@ async def _(parma: HandleRequest) -> Result:
|
|||||||
|
|
||||||
@router.post("/delete_request", dependencies=[authentication()], description="忽略请求")
|
@router.post("/delete_request", dependencies=[authentication()], description="忽略请求")
|
||||||
async def _(parma: HandleRequest) -> Result:
|
async def _(parma: HandleRequest) -> Result:
|
||||||
await FgRequest.expire(parma.id)
|
await FgRequest.ignore(parma.id)
|
||||||
return Result.ok(info="成功处理了请求!")
|
return Result.ok(info="成功处理了请求!")
|
||||||
|
|
||||||
|
|
||||||
@ -233,25 +242,25 @@ async def _(parma: HandleRequest) -> Result:
|
|||||||
bot_id = parma.bot_id
|
bot_id = parma.bot_id
|
||||||
if bot_id not in nonebot.get_bots():
|
if bot_id not in nonebot.get_bots():
|
||||||
return Result.warning_("指定Bot未连接...")
|
return Result.warning_("指定Bot未连接...")
|
||||||
if parma.request_type == "group":
|
if req := await FgRequest.get_or_none(id=parma.id):
|
||||||
if req := await FgRequest.get_or_none(id=parma.id):
|
if group := await GroupConsole.get_group(group_id=req.group_id):
|
||||||
if group := await GroupConsole.get_or_none(group_id=req.group_id):
|
group.group_flag = 1
|
||||||
await group.update_or_create(group_flag=1)
|
await group.save(update_fields=["group_flag"])
|
||||||
else:
|
|
||||||
group_info = await bots[bot_id].get_group_info(
|
|
||||||
group_id=req.group_id
|
|
||||||
)
|
|
||||||
await GroupConsole.update_or_create(
|
|
||||||
group_id=str(group_info["group_id"]),
|
|
||||||
defaults={
|
|
||||||
"group_name": group_info["group_name"],
|
|
||||||
"max_member_count": group_info["max_member_count"],
|
|
||||||
"member_count": group_info["member_count"],
|
|
||||||
"group_flag": 1,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
return Result.warning_("未找到此Id请求...")
|
group_info = await bots[bot_id].get_group_info(
|
||||||
|
group_id=req.group_id
|
||||||
|
)
|
||||||
|
await GroupConsole.update_or_create(
|
||||||
|
group_id=str(group_info["group_id"]),
|
||||||
|
defaults={
|
||||||
|
"group_name": group_info["group_name"],
|
||||||
|
"max_member_count": group_info["max_member_count"],
|
||||||
|
"member_count": group_info["member_count"],
|
||||||
|
"group_flag": 1,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return Result.warning_("未找到此Id请求...")
|
||||||
try:
|
try:
|
||||||
await FgRequest.approve(bots[bot_id], parma.id)
|
await FgRequest.approve(bots[bot_id], parma.id)
|
||||||
return Result.ok(info="成功处理了请求!")
|
return Result.ok(info="成功处理了请求!")
|
||||||
@ -393,6 +402,15 @@ async def _(bot_id: str, group_id: str) -> Result:
|
|||||||
status=task[0] not in split_task,
|
status=task[0] not in split_task,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
for task in all_task:
|
||||||
|
task_list.append(
|
||||||
|
Task(
|
||||||
|
name=task[0],
|
||||||
|
zh_name=task_module2name.get(task[0]) or task[0],
|
||||||
|
status=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
group_detail = GroupDetail(
|
group_detail = GroupDetail(
|
||||||
group_id=group_id,
|
group_id=group_id,
|
||||||
ava_url=GROUP_AVA_URL.format(group_id, group_id),
|
ava_url=GROUP_AVA_URL.format(group_id, group_id),
|
||||||
@ -507,7 +525,6 @@ async def _(websocket: WebSocket):
|
|||||||
async def log_listener(log: str):
|
async def log_listener(log: str):
|
||||||
global MSG_LIST, ID2NAME
|
global MSG_LIST, ID2NAME
|
||||||
sub_log = re.sub(SUB_PATTERN, "", log)
|
sub_log = re.sub(SUB_PATTERN, "", log)
|
||||||
img_list = re.findall(IMAGE_PATTERN, sub_log)
|
|
||||||
if "message.private.friend" in log:
|
if "message.private.friend" in log:
|
||||||
if message := await message_handle(sub_log, "private"):
|
if message := await message_handle(sub_log, "private"):
|
||||||
await websocket.send_json(message.dict())
|
await websocket.send_json(message.dict())
|
||||||
|
|||||||
@ -132,8 +132,6 @@ class HandleRequest(BaseModel):
|
|||||||
"""bot_id"""
|
"""bot_id"""
|
||||||
id: int
|
id: int
|
||||||
"""数据id"""
|
"""数据id"""
|
||||||
request_type: Literal["private", "group"]
|
|
||||||
"""类型"""
|
|
||||||
|
|
||||||
|
|
||||||
class LeaveGroup(BaseModel):
|
class LeaveGroup(BaseModel):
|
||||||
|
|||||||
@ -32,7 +32,7 @@ async def _(
|
|||||||
plugin_list: list[PluginInfo] = []
|
plugin_list: list[PluginInfo] = []
|
||||||
query = DbPluginInfo
|
query = DbPluginInfo
|
||||||
if plugin_type:
|
if plugin_type:
|
||||||
query = query.filter(plugin_type__in=plugin_type)
|
query = query.filter(plugin_type__in=plugin_type, load_status=True)
|
||||||
if menu_type:
|
if menu_type:
|
||||||
query = query.filter(menu_type=menu_type)
|
query = query.filter(menu_type=menu_type)
|
||||||
plugins = await query.all()
|
plugins = await query.all()
|
||||||
@ -62,16 +62,17 @@ async def _(
|
|||||||
async def _() -> Result:
|
async def _() -> Result:
|
||||||
plugin_count = PluginCount()
|
plugin_count = PluginCount()
|
||||||
plugin_count.normal = await DbPluginInfo.filter(
|
plugin_count.normal = await DbPluginInfo.filter(
|
||||||
plugin_type=PluginType.NORMAL
|
plugin_type=PluginType.NORMAL, load_status=True
|
||||||
).count()
|
).count()
|
||||||
plugin_count.admin = await DbPluginInfo.filter(
|
plugin_count.admin = await DbPluginInfo.filter(
|
||||||
plugin_type__in=[PluginType.ADMIN, PluginType.SUPER_AND_ADMIN]
|
plugin_type__in=[PluginType.ADMIN, PluginType.SUPER_AND_ADMIN], load_status=True
|
||||||
).count()
|
).count()
|
||||||
plugin_count.superuser = await DbPluginInfo.filter(
|
plugin_count.superuser = await DbPluginInfo.filter(
|
||||||
plugin_type=[PluginType.SUPERUSER, PluginType.SUPER_AND_ADMIN]
|
plugin_type__in=[PluginType.SUPERUSER, PluginType.SUPER_AND_ADMIN],
|
||||||
|
load_status=True,
|
||||||
).count()
|
).count()
|
||||||
plugin_count.other = await DbPluginInfo.filter(
|
plugin_count.other = await DbPluginInfo.filter(
|
||||||
plugin_type=PluginType.HIDDEN
|
plugin_type=PluginType.HIDDEN, load_status=True
|
||||||
).count()
|
).count()
|
||||||
return Result.ok(plugin_count)
|
return Result.ok(plugin_count)
|
||||||
|
|
||||||
@ -81,7 +82,9 @@ async def _() -> Result:
|
|||||||
)
|
)
|
||||||
async def _(plugin: UpdatePlugin) -> Result:
|
async def _(plugin: UpdatePlugin) -> Result:
|
||||||
try:
|
try:
|
||||||
db_plugin = await DbPluginInfo.get_or_none(module=plugin.module)
|
db_plugin = await DbPluginInfo.get_or_none(
|
||||||
|
module=plugin.module, load_status=True
|
||||||
|
)
|
||||||
if not db_plugin:
|
if not db_plugin:
|
||||||
return Result.fail("插件不存在...")
|
return Result.fail("插件不存在...")
|
||||||
db_plugin.default_status = plugin.default_status
|
db_plugin.default_status = plugin.default_status
|
||||||
@ -111,7 +114,7 @@ async def _(plugin: UpdatePlugin) -> Result:
|
|||||||
|
|
||||||
@router.post("/change_switch", dependencies=[authentication()], description="开关插件")
|
@router.post("/change_switch", dependencies=[authentication()], description="开关插件")
|
||||||
async def _(param: PluginSwitch) -> Result:
|
async def _(param: PluginSwitch) -> Result:
|
||||||
db_plugin = await DbPluginInfo.get_or_none(module=param.module)
|
db_plugin = await DbPluginInfo.get_or_none(module=param.module, load_status=True)
|
||||||
if not db_plugin:
|
if not db_plugin:
|
||||||
return Result.fail("插件不存在...")
|
return Result.fail("插件不存在...")
|
||||||
if not param.status:
|
if not param.status:
|
||||||
@ -131,14 +134,14 @@ async def _() -> Result:
|
|||||||
menu_type_list = []
|
menu_type_list = []
|
||||||
result = await DbPluginInfo.annotate().values_list("menu_type", flat=True)
|
result = await DbPluginInfo.annotate().values_list("menu_type", flat=True)
|
||||||
for r in result:
|
for r in result:
|
||||||
if r not in menu_type_list:
|
if r not in menu_type_list and r:
|
||||||
menu_type_list.append(r)
|
menu_type_list.append(r)
|
||||||
return Result.ok(menu_type_list)
|
return Result.ok(menu_type_list)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/get_plugin", dependencies=[authentication()], description="获取插件详情")
|
@router.get("/get_plugin", dependencies=[authentication()], description="获取插件详情")
|
||||||
async def _(module: str) -> Result:
|
async def _(module: str) -> Result:
|
||||||
db_plugin = await DbPluginInfo.get_or_none(module=module)
|
db_plugin = await DbPluginInfo.get_or_none(module=module, load_status=True)
|
||||||
if not db_plugin:
|
if not db_plugin:
|
||||||
return Result.fail("插件不存在...")
|
return Result.fail("插件不存在...")
|
||||||
config_list = []
|
config_list = []
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user