From fe68e0b1fd6f0008bb5646cbac6c9bd193f40ca5 Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 17 Jul 2020 01:13:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0sticker=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagermaid/modules/sticker.py | 72 +++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/pagermaid/modules/sticker.py b/pagermaid/modules/sticker.py index ae252f9..fff1f1e 100644 --- a/pagermaid/modules/sticker.py +++ b/pagermaid/modules/sticker.py @@ -5,6 +5,7 @@ from os import remove from urllib import request from io import BytesIO from telethon.tl.types import DocumentAttributeFilename, MessageMediaPhoto +from telethon.errors.common import AlreadyInConversationError from PIL import Image from math import floor from pagermaid import bot @@ -91,36 +92,47 @@ async def sticker(context): if " A Telegram user has created the Sticker Set." not in \ http_response: - async with bot.conversation('Stickers') as conversation: - await conversation.send_message('/addsticker') - await conversation.get_response() - await bot.send_read_acknowledge(conversation.chat_id) - await conversation.send_message(pack_name) - chat_response = await conversation.get_response() - while chat_response.text == "Whoa! That's probably enough stickers for one pack, give it a break. \ -A pack can't have more than 120 stickers at the moment.": - pack += 1 - pack_name = f"{user.username}_{pack}" - pack_title = f"@{user.username} 的私藏 ({pack})" - await context.edit("切换到私藏 " + str(pack) + - " 上一个贴纸包已满 . . .") - await conversation.send_message(pack_name) - chat_response = await conversation.get_response() - if chat_response.text == "Invalid pack selected.": - await add_sticker(conversation, command, pack_title, pack_name, animated, message, - context, file, emoji) - await context.edit( - f"这张图片/贴纸已经被添加到 [这个](t.me/addstickers/{pack_name}) 贴纸包。", - parse_mode='md') - return - await upload_sticker(animated, message, context, file, conversation) - await conversation.get_response() - await conversation.send_message(emoji) - await bot.send_read_acknowledge(conversation.chat_id) - await conversation.get_response() - await conversation.send_message('/done') - await conversation.get_response() - await bot.send_read_acknowledge(conversation.chat_id) + conversation = '' + for i in range(0,10): # 最多重试100次 + try: + async with bot.conversation('Stickers') as conversation: + await conversation.send_message('/addsticker') + await conversation.get_response() + await bot.send_read_acknowledge(conversation.chat_id) + await conversation.send_message(pack_name) + chat_response = await conversation.get_response() + while chat_response.text == "Whoa! That's probably enough stickers for one pack, give it a break. \ + A pack can't have more than 120 stickers at the moment.": + pack += 1 + pack_name = f"{user.username}_{pack}" + pack_title = f"@{user.username} 的私藏 ({pack})" + await context.edit("切换到私藏 " + str(pack) + + " 上一个贴纸包已满 . . .") + await conversation.send_message(pack_name) + chat_response = await conversation.get_response() + if chat_response.text == "Invalid pack selected.": + await add_sticker(conversation, command, pack_title, pack_name, animated, message, + context, file, emoji) + await context.edit( + f"这张图片/贴纸已经被添加到 [这个](t.me/addstickers/{pack_name}) 贴纸包。", + parse_mode='md') + return + await upload_sticker(animated, message, context, file, conversation) + await conversation.get_response() + await conversation.send_message(emoji) + await bot.send_read_acknowledge(conversation.chat_id) + await conversation.get_response() + 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: await context.edit("贴纸包不存在,正在创建 . . .") async with bot.conversation('Stickers') as conversation: From a821b1433fa7a75a2e84e622480651f58db0c9cb Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 17 Jul 2020 01:14:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagermaid/modules/sticker.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pagermaid/modules/sticker.py b/pagermaid/modules/sticker.py index fff1f1e..5b9dd28 100644 --- a/pagermaid/modules/sticker.py +++ b/pagermaid/modules/sticker.py @@ -92,7 +92,6 @@ async def sticker(context): if " A Telegram user has created the Sticker Set." not in \ http_response: - conversation = '' for i in range(0,10): # 最多重试100次 try: async with bot.conversation('Stickers') as conversation: