Added skipping of user with invalid username

This commit is contained in:
Анатолий Богомолов 2024-02-08 17:59:42 +10:00
parent 8dce3b1f62
commit 94302d09e9
1 changed files with 11 additions and 8 deletions

View File

@ -23,7 +23,8 @@ from telethon.errors.rpcerrorlist import (
UsersTooMuchError, UsersTooMuchError,
UserChannelsTooMuchError, UserChannelsTooMuchError,
UserIsBlockedError, UserIsBlockedError,
YouBlockedUserError YouBlockedUserError,
UsernameInvalidError,
) )
class PaperClient(TelegramClient): class PaperClient(TelegramClient):
@ -93,6 +94,7 @@ class PaperClient(TelegramClient):
return await super().get_participants(group, *args, **kwargs) return await super().get_participants(group, *args, **kwargs)
async def __cast_to_entity(self, entity: Entity | EntityLike) -> Entity: async def __cast_to_entity(self, entity: Entity | EntityLike) -> Entity:
try:
if not isinstance(entity, Entity): if not isinstance(entity, Entity):
if hasattr(entity, "username"): if hasattr(entity, "username"):
entity = await self.get_entity(entity.username) entity = await self.get_entity(entity.username)
@ -100,4 +102,5 @@ class PaperClient(TelegramClient):
entity = await self.get_entity(entity) entity = await self.get_entity(entity)
return entity # type: ignore return entity # type: ignore
except UsernameInvalidError as e:
raise IgnoreException(e)