Ignore avatar download errors
This commit is contained in:
@@ -17,7 +17,7 @@ from telethon.tl.functions.messages import (GetFullChatRequest, EditChatAdminReq
|
|||||||
CreateChatRequest, AddChatUserRequest)
|
CreateChatRequest, AddChatUserRequest)
|
||||||
from telethon.tl.functions.channels import (GetParticipantsRequest, CreateChannelRequest,
|
from telethon.tl.functions.channels import (GetParticipantsRequest, CreateChannelRequest,
|
||||||
InviteToChannelRequest)
|
InviteToChannelRequest)
|
||||||
from telethon.errors.rpc_error_list import ChatAdminRequiredError
|
from telethon.errors.rpc_error_list import ChatAdminRequiredError, LocationInvalidError
|
||||||
from telethon.tl.types import *
|
from telethon.tl.types import *
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
@@ -210,7 +210,10 @@ class Portal:
|
|||||||
def update_avatar(self, user, photo, intent=None):
|
def update_avatar(self, user, photo, intent=None):
|
||||||
photo_id = f"{photo.volume_id}-{photo.local_id}"
|
photo_id = f"{photo.volume_id}-{photo.local_id}"
|
||||||
if self.photo_id != photo_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)
|
uploaded = self.main_intent.upload_file(file)
|
||||||
self.main_intent.set_room_avatar(self.mxid, uploaded["content_uri"])
|
self.main_intent.set_room_avatar(self.mxid, uploaded["content_uri"])
|
||||||
self.photo_id = photo_id
|
self.photo_id = photo_id
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
import re
|
import re
|
||||||
from telethon.tl.types import UserProfilePhoto
|
from telethon.tl.types import UserProfilePhoto
|
||||||
|
from telethon.errors.rpc_error_list import LocationInvalidError
|
||||||
from .db import Puppet as DBPuppet
|
from .db import Puppet as DBPuppet
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
@@ -105,7 +106,10 @@ class Puppet:
|
|||||||
def update_avatar(self, source, photo):
|
def update_avatar(self, source, photo):
|
||||||
photo_id = f"{photo.volume_id}-{photo.local_id}"
|
photo_id = f"{photo.volume_id}-{photo.local_id}"
|
||||||
if self.photo_id != photo_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)
|
uploaded = self.intent.upload_file(file)
|
||||||
self.intent.set_avatar(uploaded["content_uri"])
|
self.intent.set_avatar(uploaded["content_uri"])
|
||||||
self.photo_id = photo_id
|
self.photo_id = photo_id
|
||||||
|
|||||||
Reference in New Issue
Block a user