mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 12:50:03 +08:00
feat✨: 新增Web UI功能及数据库、日志等API接口
This commit is contained in:
@@ -9,7 +9,9 @@ from zhenxun.utils.exception import NotFoundError
|
||||
class FgRequest(Model):
|
||||
id = fields.IntField(pk=True, generated=True, auto_increment=True)
|
||||
"""自增id"""
|
||||
request_type = fields.CharEnumField(RequestType, default=None, description="请求类型")
|
||||
request_type = fields.CharEnumField(
|
||||
RequestType, default=None, description="请求类型"
|
||||
)
|
||||
"""请求类型"""
|
||||
platform = fields.CharField(255, description="平台")
|
||||
"""平台"""
|
||||
@@ -25,7 +27,9 @@ class FgRequest(Model):
|
||||
"""对象名称"""
|
||||
comment = fields.CharField(max_length=255, null=True, description="验证信息")
|
||||
"""验证信息"""
|
||||
handle_type = fields.CharEnumField(RequestHandleType, null=True, description="处理类型")
|
||||
handle_type = fields.CharEnumField(
|
||||
RequestHandleType, null=True, description="处理类型"
|
||||
)
|
||||
"""处理类型"""
|
||||
|
||||
class Meta:
|
||||
@@ -33,53 +37,61 @@ class FgRequest(Model):
|
||||
table_description = "好友群组请求"
|
||||
|
||||
@classmethod
|
||||
async def approve(cls, bot: Bot, id: int, request_type: RequestType):
|
||||
async def approve(cls, bot: Bot, id: int):
|
||||
"""同意请求
|
||||
|
||||
参数:
|
||||
bot: Bot
|
||||
id: 请求id
|
||||
request_type: 请求类型
|
||||
|
||||
异常:
|
||||
NotFoundError: 未发现请求
|
||||
"""
|
||||
await cls._handle_request(bot, id, request_type, RequestHandleType.APPROVE)
|
||||
await cls._handle_request(bot, id, RequestHandleType.APPROVE)
|
||||
|
||||
@classmethod
|
||||
async def refused(cls, bot: Bot, id: int, request_type: RequestType):
|
||||
async def refused(cls, bot: Bot, id: int):
|
||||
"""拒绝请求
|
||||
|
||||
参数:
|
||||
bot: Bot
|
||||
id: 请求id
|
||||
request_type: 请求类型
|
||||
|
||||
异常:
|
||||
NotFoundError: 未发现请求
|
||||
"""
|
||||
await cls._handle_request(bot, id, request_type, RequestHandleType.REFUSED)
|
||||
await cls._handle_request(bot, id, RequestHandleType.REFUSED)
|
||||
|
||||
@classmethod
|
||||
async def ignore(cls, bot: Bot, id: int, request_type: RequestType):
|
||||
async def ignore(cls, id: int):
|
||||
"""忽略请求
|
||||
|
||||
参数:
|
||||
id: 请求id
|
||||
|
||||
异常:
|
||||
NotFoundError: 未发现请求
|
||||
"""
|
||||
await cls._handle_request(None, id, RequestHandleType.IGNORE)
|
||||
|
||||
@classmethod
|
||||
async def expire(cls, id: int):
|
||||
"""忽略请求
|
||||
|
||||
参数:
|
||||
bot: Bot
|
||||
id: 请求id
|
||||
request_type: 请求类型
|
||||
|
||||
异常:
|
||||
NotFoundError: 未发现请求
|
||||
"""
|
||||
await cls._handle_request(bot, id, request_type, RequestHandleType.IGNORE)
|
||||
await cls._handle_request(None, id, RequestHandleType.EXPIRE)
|
||||
|
||||
@classmethod
|
||||
async def _handle_request(
|
||||
cls,
|
||||
bot: Bot,
|
||||
bot: Bot | None,
|
||||
id: int,
|
||||
request_type: RequestType,
|
||||
handle_type: RequestHandleType,
|
||||
):
|
||||
"""处理请求
|
||||
@@ -87,19 +99,21 @@ class FgRequest(Model):
|
||||
参数:
|
||||
bot: Bot
|
||||
id: 请求id
|
||||
request_type: 请求类型
|
||||
handle_type: 处理类型
|
||||
|
||||
异常:
|
||||
NotFoundError: 未发现请求
|
||||
"""
|
||||
req = await cls.get_or_none(id=id, request_type=request_type)
|
||||
req = await cls.get_or_none(id=id)
|
||||
if not req:
|
||||
raise NotFoundError
|
||||
req.handle_type = RequestHandleType
|
||||
await req.save(update_fields=["handle_type"])
|
||||
if handle_type != RequestHandleType.IGNORE:
|
||||
if request_type == RequestType.FRIEND:
|
||||
if bot and handle_type not in [
|
||||
RequestHandleType.IGNORE,
|
||||
RequestHandleType.EXPIRE,
|
||||
]:
|
||||
if req.request_type == RequestType.FRIEND:
|
||||
await bot.set_friend_add_request(
|
||||
flag=req.flag, approve=handle_type == RequestHandleType.APPROVE
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user