mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-25 10:02:17 +00:00
zpr support topic group (#96)
Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com>
This commit is contained in:
parent
3f47dc785e
commit
1e4c977423
21
zpr/main.py
21
zpr/main.py
@ -3,9 +3,13 @@ import shutil
|
||||
from os import makedirs
|
||||
from os.path import exists, dirname, abspath
|
||||
from pagermaid.listener import listener
|
||||
from pagermaid.single_utils import safe_remove
|
||||
from pagermaid.enums import Client, Message, AsyncClient
|
||||
from pyrogram.types import InputMediaPhoto
|
||||
from pyrogram.errors import RPCError
|
||||
|
||||
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'
|
||||
}
|
||||
|
||||
async def get_result(message, request, r18=0):
|
||||
# r18: 0为非 R18,1为 R18,2为混合(在库中的分类,不等同于作品本身的 R18 标识)
|
||||
@ -14,9 +18,7 @@ async def get_result(message, request, r18=0):
|
||||
zpr_path = f"{dirname(abspath(__file__))}/zpr/"
|
||||
if not exists(zpr_path):
|
||||
makedirs(zpr_path)
|
||||
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}"), headers=headers, timeout=10)
|
||||
@ -41,11 +43,13 @@ async def get_result(message, request, r18=0):
|
||||
setuList.append(InputMediaPhoto(f"{zpr_path}{imgname}"))
|
||||
return setuList, zpr_path, des if setuList else None
|
||||
|
||||
|
||||
@listener(command="zpr",
|
||||
description="随机获取一组涩涩纸片人。",
|
||||
parameters="{r18}")
|
||||
async def zpr(client: Client, message: Message, request: AsyncClient):
|
||||
arguments = message.arguments.upper().strip()
|
||||
message_thread_id = message.reply_to_top_message_id or message.reply_to_message_id
|
||||
message = await message.edit("正在前往二次元。。。")
|
||||
try:
|
||||
photoList, zpr_path, des = await get_result(message, request, r18=1 if arguments == "R18" else 0)
|
||||
@ -53,9 +57,12 @@ async def zpr(client: Client, message: Message, request: AsyncClient):
|
||||
shutil.rmtree(zpr_path)
|
||||
return await message.edit(des)
|
||||
with contextlib.suppress(Exception):
|
||||
message = await message.edit("传送中。。。")
|
||||
await client.send_media_group(message.chat.id, photoList)
|
||||
await message.edit("传送中。。。")
|
||||
try:
|
||||
await client.send_media_group(message.chat.id, photoList, reply_to_message_id=message_thread_id)
|
||||
except RPCError as e:
|
||||
return await message.edit("此群组不允许发送媒体。" if e.ID == "CHAT_SEND_MEDIA_FORBIDDEN" else f"发生错误:\n`{e}`")
|
||||
except Exception as e:
|
||||
await client.send_message(message.chat.id, f"{des}\n\n错误信息:\n`{e}`")
|
||||
return await message.edit(f"发生错误:\n`{e}`")
|
||||
shutil.rmtree(zpr_path)
|
||||
await message.safe_delete()
|
||||
|
Loading…
Reference in New Issue
Block a user