From 17bf5b2d90cd3524e217a6502d15b5a4d07bbdce Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Wed, 14 Apr 2021 00:43:23 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20sticker=20Not=20completely=20fix?= =?UTF-8?q?=20decode=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 sticker 不完全修复极端条件下的贴纸名生成错误 --- pagermaid/modules/sticker.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pagermaid/modules/sticker.py b/pagermaid/modules/sticker.py index adc2304..f23de46 100644 --- a/pagermaid/modules/sticker.py +++ b/pagermaid/modules/sticker.py @@ -105,8 +105,15 @@ async def sticker(context): pack_title += " (animated)" command = '/newanimated' - response = request.urlopen( - request.Request(f'http://t.me/addstickers/{pack_name}'), context=ssl.create_default_context(cafile=certifi.where())) + try: + response = request.urlopen( + request.Request(f'http://t.me/addstickers/{pack_name}'), context=ssl.create_default_context(cafile=certifi.where())) + except UnicodeEncodeError: + pack_name = 's' + hex(context.sender.id)[2:] + if animated: + pack_name = 's' + hex(context.sender.id)[2:] + '_animated' + response = request.urlopen( + request.Request(f'http://t.me/addstickers/{pack_name}'), context=ssl.create_default_context(cafile=certifi.where())) if not response.status == 200: try: await context.edit(lang('sticker_telegram_server_error'))