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,11 +94,13 @@ 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:
if not isinstance(entity, Entity): try:
if hasattr(entity, "username"): if not isinstance(entity, Entity):
entity = await self.get_entity(entity.username) if hasattr(entity, "username"):
else: entity = await self.get_entity(entity.username)
entity = await self.get_entity(entity) else:
entity = await self.get_entity(entity)
return entity # type: ignore
return entity # type: ignore
except UsernameInvalidError as e:
raise IgnoreException(e)