From 94302d09e9e18cb1e0a2f818a87296fd1dd59efe Mon Sep 17 00:00:00 2001 From: winet Date: Thu, 8 Feb 2024 17:59:42 +1000 Subject: [PATCH] Added skipping of user with invalid username --- paper/client.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/paper/client.py b/paper/client.py index 07d365c..32ca1d1 100644 --- a/paper/client.py +++ b/paper/client.py @@ -23,7 +23,8 @@ from telethon.errors.rpcerrorlist import ( UsersTooMuchError, UserChannelsTooMuchError, UserIsBlockedError, - YouBlockedUserError + YouBlockedUserError, + UsernameInvalidError, ) class PaperClient(TelegramClient): @@ -93,11 +94,13 @@ class PaperClient(TelegramClient): return await super().get_participants(group, *args, **kwargs) async def __cast_to_entity(self, entity: Entity | EntityLike) -> Entity: - if not isinstance(entity, Entity): - if hasattr(entity, "username"): - entity = await self.get_entity(entity.username) - else: - entity = await self.get_entity(entity) - - return entity # type: ignore + try: + if not isinstance(entity, Entity): + if hasattr(entity, "username"): + entity = await self.get_entity(entity.username) + else: + entity = await self.get_entity(entity) + return entity # type: ignore + except UsernameInvalidError as e: + raise IgnoreException(e)