From 4599018118aa92d342aa0677b6f50913aef64189 Mon Sep 17 00:00:00 2001 From: Sergey Date: Sat, 24 Oct 2020 21:57:13 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=87=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=B3=D0=B8=D1=84=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vk_messages.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/vk_messages.py b/vk_messages.py index 89e2068..4b0911b 100644 --- a/vk_messages.py +++ b/vk_messages.py @@ -992,11 +992,15 @@ async def process_attachment(attachment, token=None): elif atype == 'doc': ext = attachment[atype]['ext'] if ext == 'gif': - size = int(attachment[atype]['preview']['video']['file_size']) - gif_url = attachment[atype]['preview']['video']['src'] - if size > MAX_FILE_SIZE: - return {'content': f'GIF', 'type': 'text'} - return {'content': gif_url, 'type': 'document'} + if 'video' in attachment[atype]['preview']: + size = int(attachment[atype]['preview']['video']['file_size']) + gif_url = attachment[atype]['preview']['video']['src'] + if size > MAX_FILE_SIZE: + return {'content': f'GIF', 'type': 'text'} + return {'content': gif_url, 'type': 'document'} + else: + photo_url = attachment[atype]['preview']['photo']['sizes'][-1]['src'] + return {'content': photo_url, 'type': 'photo'} # elif 'preview' in attachment[atype] and attachment[atype]['preview'].get('graffiti'): # graffiti_url = attachment[atype]['preview']['photo']['sizes'][-1]['src'] # with aiohttp.ClientSession() as session: