PagerMaid-Pyro/pagermaid/web/api/ignore_groups.py

47 lines
1.3 KiB
Python
Raw Permalink Normal View History

2023-01-31 16:24:56 +00:00
from fastapi import APIRouter
from starlette.responses import JSONResponse
from pagermaid.common.ignore import ignore_groups_manager, get_group_list
from pagermaid.web.api import authentication
route = APIRouter()
2023-03-12 03:56:01 +00:00
@route.get(
"/get_ignore_group_list",
response_class=JSONResponse,
dependencies=[authentication()],
)
2023-01-31 16:24:56 +00:00
async def get_ignore_group_list():
try:
groups = []
for data in await get_group_list():
data["status"] = ignore_groups_manager.check_id(data["id"])
groups.append(data)
2023-03-12 03:56:01 +00:00
return {"status": 0, "msg": "ok", "data": {"groups": groups}}
2023-01-31 16:24:56 +00:00
except BaseException:
2023-03-12 03:56:01 +00:00
return {"status": -100, "msg": "获取群组列表失败"}
2023-01-31 16:24:56 +00:00
2023-03-12 03:56:01 +00:00
@route.post(
"/set_ignore_group_status",
response_class=JSONResponse,
dependencies=[authentication()],
)
2023-01-31 16:24:56 +00:00
async def set_ignore_group_status(data: dict):
2023-03-12 03:56:01 +00:00
cid: int = data.get("id")
status: bool = data.get("status")
2023-01-31 16:24:56 +00:00
if status:
ignore_groups_manager.add_id(cid)
else:
ignore_groups_manager.del_id(cid)
2023-03-12 03:56:01 +00:00
return {"status": 0, "msg": f'成功{"忽略" if status else "取消忽略"} {cid}'}
2023-01-31 16:24:56 +00:00
2023-03-12 03:56:01 +00:00
@route.post(
"/clear_ignore_group", response_class=JSONResponse, dependencies=[authentication()]
)
2023-01-31 16:24:56 +00:00
async def clear_ignore_group():
ignore_groups_manager.clear_subs()
2023-03-12 03:56:01 +00:00
return {"status": 0, "msg": "成功清空忽略列表"}