From 6a8b1ce91df87e2e99ac8e7ad622fdcf787a7c66 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 28 Jan 2018 22:04:54 +0200 Subject: [PATCH] Ignore avatar download errors --- mautrix_telegram/portal.py | 7 +++++-- mautrix_telegram/puppet.py | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 11432de5..a03211bf 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -17,7 +17,7 @@ from telethon.tl.functions.messages import (GetFullChatRequest, EditChatAdminReq CreateChatRequest, AddChatUserRequest) from telethon.tl.functions.channels import (GetParticipantsRequest, CreateChannelRequest, InviteToChannelRequest) -from telethon.errors.rpc_error_list import ChatAdminRequiredError +from telethon.errors.rpc_error_list import ChatAdminRequiredError, LocationInvalidError from telethon.tl.types import * from PIL import Image from io import BytesIO @@ -210,7 +210,10 @@ class Portal: def update_avatar(self, user, photo, intent=None): photo_id = f"{photo.volume_id}-{photo.local_id}" if self.photo_id != photo_id: - file = user.download_file(photo) + try: + file = user.download_file(photo) + except LocationInvalidError: + return False uploaded = self.main_intent.upload_file(file) self.main_intent.set_room_avatar(self.mxid, uploaded["content_uri"]) self.photo_id = photo_id diff --git a/mautrix_telegram/puppet.py b/mautrix_telegram/puppet.py index 8f4284ad..bad72138 100644 --- a/mautrix_telegram/puppet.py +++ b/mautrix_telegram/puppet.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import re from telethon.tl.types import UserProfilePhoto +from telethon.errors.rpc_error_list import LocationInvalidError from .db import Puppet as DBPuppet config = None @@ -105,7 +106,10 @@ class Puppet: def update_avatar(self, source, photo): photo_id = f"{photo.volume_id}-{photo.local_id}" if self.photo_id != photo_id: - file = source.download_file(photo) + try: + file = source.download_file(photo) + except LocationInvalidError: + return False uploaded = self.intent.upload_file(file) self.intent.set_avatar(uploaded["content_uri"]) self.photo_id = photo_id