批量修复 Topic Group

This commit is contained in:
xtaodada 2022-11-21 19:38:51 +08:00
parent a6bbbdd005
commit c49653b5e4
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
11 changed files with 68 additions and 26 deletions

View File

@ -41,13 +41,17 @@ async def bingwall(message: Message):
filename,
caption=f"#bing wallpaper\n"
f"{str(copy_right)}",
quote=False)
quote=False,
reply_to_message_id=message.reply_to_top_message_id,
)
else:
await message.reply_photo(
filename,
caption=f"#bing wallpaper\n"
f"{str(copy_right)}",
quote=False)
quote=False,
reply_to_message_id=message.reply_to_top_message_id,
)
status = True
break # 成功了就赶紧结束啦!
except Exception:

View File

@ -70,10 +70,13 @@ async def chat_transfer(message: Message):
message: Message = await message.edit("导出中...")
num = await export_chat_to_csv()
if num:
await bot.send_document(message.chat.id,
"chats.csv",
caption=f"对话导出文件,成功导出了 {num} 个群组/频道",
thumb=f"pagermaid{sep}assets{sep}logo.jpg",)
await bot.send_document(
message.chat.id,
"chats.csv",
caption=f"对话导出文件,成功导出了 {num} 个群组/频道",
thumb=f"pagermaid{sep}assets{sep}logo.jpg",
reply_to_message_id=message.reply_to_top_message_id,
)
safe_remove("chats.csv")
await message.safe_delete()
else:

View File

@ -450,6 +450,7 @@ async def eat(client_: Client, context: Message):
await client_.send_document(
context.chat.id,
f"plugins{sep}eat{sep}eat.webp",
reply_to_message_id=context.reply_to_top_message_id
)
await final_msg.safe_delete()
except TypeError:

View File

@ -97,9 +97,10 @@ async def epic(message: Message):
with open("epic.jpg", "wb") as code:
code.write(r.content)
try:
await message.reply_photo("epic.jpg", caption=msg, quote=False)
await message.reply_photo("epic.jpg", caption=msg, quote=False,
reply_to_message_id=message.reply_to_top_message_id)
except Exception:
await message.reply(msg, quote=False)
await message.reply(msg, quote=False, reply_to_message_id=message.reply_to_top_message_id)
safe_remove("epic.jpg")
else:
await message.reply(msg, quote=False)

View File

@ -116,7 +116,12 @@ async def jikipedia(message: Message):
await message.edit(text, disable_web_page_preview=True)
else:
try:
await message.reply_photo(image, quote=False, caption=text)
await message.reply_photo(
image,
quote=False,
caption=text,
reply_to_message_id=message.reply_to_top_message_id,
)
await message.safe_delete()
except Exception:
await message.edit(text, disable_web_page_preview=True)

View File

@ -5,7 +5,6 @@ from math import floor
from pagermaid.listener import listener
from pagermaid.enums import Message, Client
from pagermaid.single_utils import safe_remove
async def resize_image(photo):

View File

@ -109,7 +109,12 @@ async def speedtest(client: Client, message: Message, request: AsyncClient):
if not photo:
return await msg.edit(des)
try:
await client.send_photo(message.chat.id, photo, caption=des, reply_to_message_id=message.reply_to_top_message_id or message.reply_to_message_id)
await client.send_photo(
message.chat.id,
photo,
caption=des,
reply_to_message_id=message.reply_to_top_message_id or message.reply_to_message_id,
)
except Exception:
return await msg.edit(des)
await msg.safe_delete()

View File

@ -103,10 +103,13 @@ async def sticker_transfer(message: Message):
except NoStickerSetError:
return await message.edit("没有贴纸包可以导出")
if num:
await bot.send_document(message.chat.id,
"stickers.csv",
caption=f"贴纸包导出文件,成功导出了 {num} 个贴纸包",
thumb=f"pagermaid{sep}assets{sep}logo.jpg",)
await bot.send_document(
message.chat.id,
"stickers.csv",
caption=f"贴纸包导出文件,成功导出了 {num} 个贴纸包",
thumb=f"pagermaid{sep}assets{sep}logo.jpg",
reply_to_message_id=message.reply_to_top_message_id
)
safe_remove("stickers.csv")
await message.safe_delete()
else:

View File

@ -22,6 +22,11 @@ async def tg_bg(client: Client, message: Message):
return await message.edit(f"获取失败: {str(e)}")
if bg.document:
bg_doc = Document._parse(client, document=bg.document, file_name="bg.jpg") # noqa
await client.send_document(message.chat.id, bg_doc.file_id, file_name="bg.jpg")
await client.send_document(
message.chat.id,
bg_doc.file_id,
file_name="bg.jpg",
reply_to_message_id=message.reply_to_top_message_id,
)
return await message.safe_delete()
await message.edit("获取失败,请检查 URL")

View File

@ -10,7 +10,7 @@ from pagermaid.utils import pip_install, lang
from pagermaid.enums import Message
from pagermaid.services import bot
pip_install("yt-dlp", version="==2022.9.1", alias="yt_dlp")
pip_install("yt-dlp", version="==2022.11.11", alias="yt_dlp")
import yt_dlp
@ -75,10 +75,20 @@ async def start_download(message: Message, url: str):
result['error'] = "文件太大,无法发送"
continue
try:
await bot.send_video(cid, video=file, supports_streaming=True)
await bot.send_video(
cid,
video=file,
supports_streaming=True,
reply_to_message_id=message.reply_to_top_message_id,
)
except Exception:
try:
await bot.send_document(cid, document=file, force_document=True)
await bot.send_document(
cid,
document=file,
force_document=True,
reply_to_message_id=message.reply_to_top_message_id,
)
except Exception as e:
result["status"] = False
result["error"] = str(e)

View File

@ -11,6 +11,7 @@ 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为非 R181为 R182为混合在库中的分类不等同于作品本身的 R18 标识)
# num: 图片的数量
@ -21,7 +22,11 @@ async def get_result(message, request, r18=0):
size = "regular"
des = "出错了,没有纸片人看了。"
data = await request.get((f"https://api.lolicon.app/setu/v2?num=5&r18={r18}&size={size}"), headers=headers, timeout=10)
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("已进入二次元 . . .")
@ -29,19 +34,19 @@ async def get_result(message, request, r18=0):
result = data.json()['data']
except Exception:
return None, None, "解析JSON出错。"
setuList = [] # 发送
setu_list = [] # 发送
await message.edit("努力获取中 。。。")
for i in range(5):
urls = result[i]['urls'][size].replace('i.pixiv.re', 'img.misaka.gay')
imgname = (f"{result[i]['pid']}_{i}.jpg")
img_name = f"{result[i]['pid']}_{i}.jpg"
try:
img = await request.get(urls, headers=headers, timeout=10)
with open(f"{zpr_path}{imgname}", mode="wb") as f:
with open(f"{zpr_path}{img_name}", mode="wb") as f:
f.write(img.content)
except Exception:
return None, None, "连接二次元出错。。。"
setuList.append(InputMediaPhoto(f"{zpr_path}{imgname}"))
return setuList, zpr_path, des if setuList else None
setu_list.append(InputMediaPhoto(f"{zpr_path}{img_name}"))
return setu_list, zpr_path, des if setu_list else None
@listener(command="zpr",
@ -61,7 +66,8 @@ async def zpr(client: Client, message: Message, request: AsyncClient):
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}`")
return await message.edit(
"此群组不允许发送媒体。" if e.ID == "CHAT_SEND_MEDIA_FORBIDDEN" else f"发生错误:\n`{e}`")
except Exception as e:
return await message.edit(f"发生错误:\n`{e}`")
shutil.rmtree(zpr_path)