Commit 391c99b5 authored by Pietro Saccardi's avatar Pietro Saccardi

Bugfix: handling correctly multiple PhotoSize.

parent 366d465c
......@@ -2,7 +2,7 @@ from plugins.base import PluginProcessBase, Process
from plugins.decorators import make_plugin
from plugins.processes_host import find_plugin, active_plugins
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, BaseFilter
from telegram import error as terr
from telegram import error as terr, PhotoSize
from specialized.telegram_support.auth import AuthStatus, AuthAttemptResult
import logging
from specialized.telegram_support.auth_io import save_chat_auth_storage, load_chat_auth_storage
......@@ -21,6 +21,10 @@ _log = logging.getLogger(camel_to_snake(TELEGRAM_ROOT_PLUGIN_NAME))
def extract_largest_photo_size(photo_sizes):
return max(photo_sizes, key=lambda photo_size: photo_size.width * photo_size.height)
class AuthStatusFilter(BaseFilter):
def __init__(self, chat_auth_storage, status):
self.chat_auth_storage = chat_auth_storage
......@@ -102,7 +106,11 @@ class TelegramRootPlugin(TelegramProcessBase):'Beginning upload of media %s...', str(media_obj))
msg = method(chat_id, media_obj, *args, **kwargs)
if msg:
file_id = msg.effective_attachment.file_id
attachment = msg.effective_attachment
if isinstance(attachment, list) and len(attachment) > 0 and isinstance(attachment[0], PhotoSize):
file_id = extract_largest_photo_size(attachment).file_id
file_id = attachment.file_id'Media %s uploaded as file id %s...', str(media_obj), str(file_id))
_log.error('Unable to send media %s.', str(media_obj))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment