Merge pull request #7 from leoleoasd/patch-1

修复同时添加sticker时报错
This commit is contained in:
Xtao_dada 2020-07-18 18:11:19 +08:00 committed by GitHub
commit aa2fcc773d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ from os import remove
from urllib import request from urllib import request
from io import BytesIO from io import BytesIO
from telethon.tl.types import DocumentAttributeFilename, MessageMediaPhoto from telethon.tl.types import DocumentAttributeFilename, MessageMediaPhoto
from telethon.errors.common import AlreadyInConversationError
from PIL import Image from PIL import Image
from math import floor from math import floor
from pagermaid import bot from pagermaid import bot
@ -91,36 +92,46 @@ async def sticker(context):
if " A <strong>Telegram</strong> user has created the <strong>Sticker&nbsp;Set</strong>." not in \ if " A <strong>Telegram</strong> user has created the <strong>Sticker&nbsp;Set</strong>." not in \
http_response: http_response:
async with bot.conversation('Stickers') as conversation: for i in range(0,10): # 最多重试100次
await conversation.send_message('/addsticker') try:
await conversation.get_response() async with bot.conversation('Stickers') as conversation:
await bot.send_read_acknowledge(conversation.chat_id) await conversation.send_message('/addsticker')
await conversation.send_message(pack_name) await conversation.get_response()
chat_response = await conversation.get_response() await bot.send_read_acknowledge(conversation.chat_id)
while chat_response.text == "Whoa! That's probably enough stickers for one pack, give it a break. \ await conversation.send_message(pack_name)
A pack can't have more than 120 stickers at the moment.": chat_response = await conversation.get_response()
pack += 1 while chat_response.text == "Whoa! That's probably enough stickers for one pack, give it a break. \
pack_name = f"{user.username}_{pack}" A pack can't have more than 120 stickers at the moment.":
pack_title = f"@{user.username} 的私藏 ({pack})" pack += 1
await context.edit("切换到私藏 " + str(pack) + pack_name = f"{user.username}_{pack}"
" 上一个贴纸包已满 . . .") pack_title = f"@{user.username} 的私藏 ({pack})"
await conversation.send_message(pack_name) await context.edit("切换到私藏 " + str(pack) +
chat_response = await conversation.get_response() " 上一个贴纸包已满 . . .")
if chat_response.text == "Invalid pack selected.": await conversation.send_message(pack_name)
await add_sticker(conversation, command, pack_title, pack_name, animated, message, chat_response = await conversation.get_response()
context, file, emoji) if chat_response.text == "Invalid pack selected.":
await context.edit( await add_sticker(conversation, command, pack_title, pack_name, animated, message,
f"这张图片/贴纸已经被添加到 [这个](t.me/addstickers/{pack_name}) 贴纸包。", context, file, emoji)
parse_mode='md') await context.edit(
return f"这张图片/贴纸已经被添加到 [这个](t.me/addstickers/{pack_name}) 贴纸包。",
await upload_sticker(animated, message, context, file, conversation) parse_mode='md')
await conversation.get_response() return
await conversation.send_message(emoji) await upload_sticker(animated, message, context, file, conversation)
await bot.send_read_acknowledge(conversation.chat_id) await conversation.get_response()
await conversation.get_response() await conversation.send_message(emoji)
await conversation.send_message('/done') await bot.send_read_acknowledge(conversation.chat_id)
await conversation.get_response() await conversation.get_response()
await bot.send_read_acknowledge(conversation.chat_id) await conversation.send_message('/done')
await conversation.get_response()
await bot.send_read_acknowledge(conversation.chat_id)
break
except AlreadyInConversationError:
await context.edit("另一个命令正在添加贴纸, 等待中")
await sleep(0.5)
await context.edit("另一个命令正在添加贴纸, 重试中")
pass
except Exception:
raise
else: else:
await context.edit("贴纸包不存在,正在创建 . . .") await context.edit("贴纸包不存在,正在创建 . . .")
async with bot.conversation('Stickers') as conversation: async with bot.conversation('Stickers') as conversation: