Ignore avatar download errors

This commit is contained in:
Tulir Asokan
2018-01-28 22:04:54 +02:00
parent ec5a75c0c6
commit 6a8b1ce91d
2 changed files with 10 additions and 3 deletions
+5 -2
View File
@@ -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
+5 -1
View File
@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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