🐛 修复处理问题并优化代码

This commit is contained in:
HibiKier 2024-08-02 20:46:51 +08:00
parent fdb62f7226
commit 36047693aa
5 changed files with 48 additions and 14 deletions

View File

@ -265,6 +265,8 @@ async def _(bot: Bot, event: GroupDecreaseNoticeEvent | GroupMemberDecreaseEvent
f"踢出了 {group_name}({group_id})\n"
f"日期:{str(datetime.now()).split('.')[0]}",
)
if group:
await group.delete()
return
if str(event.user_id) == bot.self_id:
"""踢出Bot"""

View File

@ -18,7 +18,7 @@ from zhenxun.models.fg_request import FgRequest
from zhenxun.models.friend_user import FriendUser
from zhenxun.models.group_console import GroupConsole
from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType, RequestType
from zhenxun.utils.enum import PluginType, RequestHandleType, RequestType
base_config = Config.get("invite_manager")
@ -95,6 +95,12 @@ async def _(bot: v12Bot | v11Bot, event: FriendRequestEvent, session: EventSessi
user_id=str(user["user_id"]), user_name=user["nickname"]
)
else:
# 旧请求全部设置为过期
await FgRequest.filter(
request_type=RequestType.FRIEND,
user_id=str(event.user_id),
handle_type__isnull=True,
).update(handle_type=RequestHandleType.EXPIRE)
await FgRequest.create(
request_type=RequestType.FRIEND,
platform=session.platform,
@ -121,9 +127,6 @@ async def _(bot: v12Bot | v11Bot, event: GroupRequestEvent, session: EventSessio
session=event.user_id,
target=event.group_id,
)
await bot.set_group_add_request(
flag=event.flag, sub_type="invite", approve=True
)
if isinstance(bot, v11Bot):
group_info = await bot.get_group_info(group_id=event.group_id)
max_member_count = group_info["max_member_count"]
@ -141,6 +144,9 @@ async def _(bot: v12Bot | v11Bot, event: GroupRequestEvent, session: EventSessio
"group_flag": 1,
},
)
await bot.set_group_add_request(
flag=event.flag, sub_type="invite", approve=True
)
except ActionFailed as e:
logger.error(
"超级用户自动同意加入群聊发生错误",
@ -169,6 +175,13 @@ async def _(bot: v12Bot | v11Bot, event: GroupRequestEvent, session: EventSessio
"请确保已经群主或群管理沟通过!\n"
"等待管理员处理吧!",
)
# 旧请求全部设置为过期
await FgRequest.filter(
request_type=RequestType.GROUP,
user_id=str(event.user_id),
group_id=str(event.group_id),
handle_type__isnull=True,
).update(handle_type=RequestHandleType.EXPIRE)
await FgRequest.create(
request_type=RequestType.GROUP,
platform=session.platform,

View File

@ -64,6 +64,7 @@ _req_matcher = on_alconna(
permission=SUPERUSER,
priority=1,
rule=to_me(),
block=True,
)
_read_matcher = on_alconna(
@ -81,6 +82,7 @@ _read_matcher = on_alconna(
permission=SUPERUSER,
priority=1,
rule=to_me(),
block=True,
)
_clear_matcher = on_alconna(
@ -98,6 +100,7 @@ _clear_matcher = on_alconna(
permission=SUPERUSER,
priority=1,
rule=to_me(),
block=True,
)
reg_arg_list = [
@ -126,7 +129,6 @@ async def _(
id: int,
arparma: Arparma,
):
request_type = RequestType.FRIEND if handle.startswith("-f") else RequestType.GROUP
type_dict = {
"a": RequestHandleType.APPROVE,
"r": RequestHandleType.REFUSED,
@ -135,11 +137,11 @@ async def _(
handle_type = type_dict[handle[-1]]
try:
if handle_type == RequestHandleType.APPROVE:
await FgRequest.approve(bot, id, request_type)
await FgRequest.approve(bot, id)
if handle_type == RequestHandleType.REFUSED:
await FgRequest.refused(bot, id, request_type)
await FgRequest.refused(bot, id)
if handle_type == RequestHandleType.IGNORE:
await FgRequest.ignore(bot, id, request_type)
await FgRequest.ignore(id)
except NotFoundError:
await Text("未发现此id的请求...").finish(reply=True)
except Exception:
@ -158,8 +160,8 @@ async def _(
if all_request := await FgRequest.filter(handle_type__isnull=True).all():
req_list = list(all_request)
req_list.reverse()
friend_req = []
group_req = []
friend_req: list[FgRequest] = []
group_req: list[FgRequest] = []
for req in req_list:
if req.request_type == RequestType.FRIEND:
friend_req.append(req)
@ -193,9 +195,14 @@ async def _(
)
await background.paste(platform_icon, (46, 10))
await background.text((150, 12), req.nickname)
comment_img = await BuildImage.build_text_image(
f"对方留言:{req.comment}", size=15, font_color=(140, 140, 143)
)
if i == 0:
comment_img = await BuildImage.build_text_image(
f"对方留言:{req.comment}", size=15, font_color=(140, 140, 143)
)
else:
comment_img = await BuildImage.build_text_image(
f"群组:{req.group_id}", size=15, font_color=(140, 140, 143)
)
await background.paste(comment_img, (150, 65))
tag = await BuildImage.build_text_image(
f"{req.platform}",

View File

@ -107,7 +107,7 @@ class FgRequest(Model):
req = await cls.get_or_none(id=id)
if not req:
raise NotFoundError
req.handle_type = RequestHandleType
req.handle_type = handle_type
await req.save(update_fields=["handle_type"])
if bot and handle_type not in [
RequestHandleType.IGNORE,

View File

@ -73,6 +73,18 @@ class BuildImage:
def size(self) -> Tuple[int, int]:
return self.markImg.size
@classmethod
def open(cls, path: str | Path) -> Self:
"""打开图片
参数:
path: 图片路径
返回:
Self: BuildImage
"""
return cls(background=path)
@classmethod
async def build_text_image(
cls,