From 8ba6a4ea4c433d7e0ecacad7046be60a617f2131 Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 8 Oct 2020 22:47:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D1=82=D0=B8=D0=BA=D0=B5=D1=80=D0=BE=D0=B2=20?= =?UTF-8?q?=D1=84=D0=BE=D1=82=D0=BA=D0=B0=D0=BC=D0=B8=20(=D1=81=D0=BF?= =?UTF-8?q?=D0=B0=D1=81=D0=B8=D0=B1=D0=BE=20=D0=92=D0=9A)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- telegram.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/telegram.py b/telegram.py index e2b35de..6fd5013 100644 --- a/telegram.py +++ b/telegram.py @@ -755,7 +755,7 @@ async def handle_contact(msg: types.Message): await handle_text(msg) -@dp.message_handler(content_types=['photo']) +@dp.message_handler(content_types=['photo', 'sticker']) async def handle_photo(msg: types.Message): user, user_created = await update_user_info(msg.from_user) tgchat, tgchat_created = await update_chat_info(msg.chat) @@ -764,7 +764,13 @@ async def handle_photo(msg: types.Message): forward = Forward.objects.filter(tgchat=tgchat).first() forward_messages_exists, message = await is_forwarding(msg.caption) message_options = await generate_send_options(msg, forward, forward_messages_exists, message) - file_id = msg.photo[-1].file_id + if msg.content_type == 'photo': + file_id = msg.photo[-1].file_id + elif msg.content_type == 'sticker': + if msg.sticker.to_python()['is_animated']: + file_id = msg.sticker.thumb.file_id + else: + file_id = msg.sticker.file_id if message_options: message_options['attachment'] = await upload_attachment(msg, vk_user, file_id, message_options['peer_id'], attachment_type='photo', @@ -780,7 +786,7 @@ async def handle_photo(msg: types.Message): await msg.reply('Ошибка при загрузке файла. Сообщение не отправлено!', parse_mode=ParseMode.HTML) -@dp.message_handler(content_types=['document', 'voice', 'audio', 'sticker']) +@dp.message_handler(content_types=['document', 'voice', 'audio']) async def handle_documents(msg: types.Message): user, user_created = await update_user_info(msg.from_user) tgchat, tgchat_created = await update_chat_info(msg.chat) @@ -807,12 +813,13 @@ async def handle_documents(msg: types.Message): if msg.content_type == 'voice': upload_attachment_options['upload_type'] = 'audio_message' - if msg.content_type == 'sticker': - if msg.sticker.to_python()['is_animated']: - file_id = msg.sticker.thumb.file_id - upload_attachment_options['upload_type'] = 'graffiti' - upload_attachment_options['rewrite_name'] = True - upload_attachment_options['default_name'] = 'graffiti.png' + # https://vk.com/wall-1_395554 + # if msg.content_type == 'sticker': + # if msg.sticker.to_python()['is_animated']: + # file_id = msg.sticker.thumb.file_id + # upload_attachment_options['upload_type'] = 'graffiti' + # upload_attachment_options['rewrite_name'] = True + # upload_attachment_options['default_name'] = 'graffiti.png' if msg.content_type == 'audio': audioname = ''