From 6b3d50d75fe845cd7b9906800349b9ba08d6ca81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=93=9C=E7=93=9C=E5=90=96?= <31442507+guaguaya66@users.noreply.github.com> Date: Sat, 15 Oct 2022 17:56:12 +0800 Subject: [PATCH] =?UTF-8?q?zpr=20=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=8F=8D=E4=BB=A3=E7=AB=99=EF=BC=8C=E5=AE=8C=E5=96=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=A1=E6=81=AF=E6=8F=90=E7=A4=BA=20(#94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sourcery AI <> Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com> --- zpr/main.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/zpr/main.py b/zpr/main.py index 84ee22b..e9bb475 100644 --- a/zpr/main.py +++ b/zpr/main.py @@ -8,9 +8,12 @@ async def get_result(message, request, r18=0): # r18: 0为非 R18,1为 R18,2为混合(在库中的分类,不等同于作品本身的 R18 标识) # num: 图片的数量 # size: 返回图片的尺寸质量 + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.42' + } size = "regular" des = "出错了,没有纸片人看了。" - data = await request.get((f"https://api.lolicon.app/setu/v2?num=5&r18={r18}&size={size}")) + data = await request.get((f"https://api.lolicon.app/setu/v2?num=5&r18={r18}&size={size}"), headers=headers, timeout=10) if data.status_code != 200: return None, None, "连接二次元大门出错。。。" await message.edit("已进入二次元 . . .") @@ -22,10 +25,10 @@ async def get_result(message, request, r18=0): delList = [] # 删除 await message.edit("努力获取中 。。。") for i in range(5): - urls = result[i]['urls'][size] - imgname = (f"{result[i]['pid']}_{i}.png") + urls = result[i]['urls'][size].replace('i.pixiv.re', 'img.misaka.gay') + imgname = (f"{result[i]['pid']}_{i}.jpg") try: - img = await request.get(urls) + img = await request.get(urls, headers=headers, timeout=10) with open(imgname, mode="wb") as f: f.write(img.content) except Exception: @@ -44,14 +47,18 @@ async def zpr(client: Client, message: Message, request: AsyncClient): try: photoList, delList, des = await get_result(message, request, r18=1 if arguments == "R18" else 0) except Exception as e: - return await message.edit(f"发生错误:{e}") + return await message.edit(f"{des}\n\n错误信息:\n`{e}`") if not photoList: return await message.edit(des) try: await message.edit("传送中。。。") await client.send_media_group(message.chat.id, photoList) + except Exception as e: + await client.send_message(message.chat.id, f"{des}\n\n错误信息:\n`{e}`") + try: for i in range(5): - safe_remove(delList[i]) - except Exception: - await client.send_message(message.chat.id, des) + if delList[i]: + safe_remove(delList[i]) + except: + pass await message.safe_delete()