sticker_transfer 修复错误

This commit is contained in:
xtaodada 2022-07-03 20:50:16 +08:00
parent f2829ec91f
commit 0638720b1d
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 19 additions and 12 deletions

View File

@ -262,10 +262,10 @@
}, },
{ {
"name": "sticker_transfer", "name": "sticker_transfer",
"version": "1.0", "version": "1.01",
"section": "chat", "section": "chat",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "3.24 kb", "size": "3.5 kb",
"supported": true, "supported": true,
"des-short": "贴纸迁移", "des-short": "贴纸迁移",
"des": "贴纸迁移。\n指令,sticker_transfer" "des": "贴纸迁移。\n指令,sticker_transfer"

View File

@ -3,6 +3,7 @@
import csv import csv
from asyncio import sleep from asyncio import sleep
from os import sep
from pyrogram.errors import StickersetInvalid, FloodWait from pyrogram.errors import StickersetInvalid, FloodWait
from pyrogram.raw.functions.messages import GetAllStickers from pyrogram.raw.functions.messages import GetAllStickers
@ -27,7 +28,7 @@ async def export_sticker_to_csv():
sticker_set.archived if hasattr(sticker_set, "archived") else False, sticker_set.archived if hasattr(sticker_set, "archived") else False,
sticker_set.animated if hasattr(sticker_set, "animated") else False, sticker_set.animated if hasattr(sticker_set, "animated") else False,
sticker_set.videos if hasattr(sticker_set, "videos") else False, ]) sticker_set.videos if hasattr(sticker_set, "videos") else False, ])
return True return len(stickers.sets)
async def import_sticker(short_name): async def import_sticker(short_name):
@ -60,25 +61,31 @@ async def import_sticker_from_csv(file_name):
@listener(command="sticker_transfer", @listener(command="sticker_transfer",
need_admin=True, need_admin=True,
parameters="导出/导入", parameters="导出/导入",
description="导出、导入已安装的贴纸") description="导出、导入已安装的贴纸")
async def sticker_transfer(message: Message): async def sticker_transfer(message: Message):
if message.arguments == "导出": if message.arguments == "导出":
await export_sticker_to_csv() num = await export_sticker_to_csv()
await bot.send_document(message.chat.id, "stickers.csv", caption="贴纸导出文件") if num:
safe_remove("stickers.csv") await bot.send_document(message.chat.id,
await message.safe_delete() "stickers.csv",
caption=f"贴纸包导出文件,成功导出了 {num} 个贴纸包",
thumb=f"pagermaid{sep}assets{sep}logo.jpg",)
safe_remove("stickers.csv")
await message.safe_delete()
else:
await message.edit("没有贴纸包可以导出")
elif message.arguments == "导入": elif message.arguments == "导入":
reply = message.reply_to_message reply = message.reply_to_message
if not reply: if not reply:
return await message.edit("❌ 请回复贴纸导出文件") return await message.edit("❌ 请回复贴纸导出文件")
if not reply.document: if not reply.document:
return await message.edit("❌ 请回复贴纸导出文件") return await message.edit("❌ 请回复贴纸导出文件")
if not reply.document.file_name.endswith(".csv"): if not reply.document.file_name.endswith(".csv"):
return await message.edit("❌ 请回复贴纸导出文件") return await message.edit("❌ 请回复贴纸导出文件")
message = await message.edit("导入中") message = await message.edit("导入中")
file_name = await reply.download() file_name = await reply.download()
success, failed = await import_sticker_from_csv(file_name) success, failed = await import_sticker_from_csv(file_name)
safe_remove(file_name) safe_remove(file_name)
await message.edit(f"导入成功 {success} 个贴纸,失败 {failed} 个贴纸") await message.edit(f"导入成功 {success} 个贴纸,失败 {failed} 个贴纸")
else: else:
await message.edit("❌ 参数错误,请选择 `导出` 或 `导入` ") await message.edit("❌ 参数错误,请选择 `导出` 或 `导入` ")