Skip to content

Commit

Permalink
Handle private chat exception
Browse files Browse the repository at this point in the history
  • Loading branch information
zuevmaxim committed Jun 12, 2024
1 parent dd5e180 commit 09ab094
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bot/scrolling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pyrogram import Client, types
from pyrogram.enums import ChatType
from pyrogram.errors import BadRequest
from pyrogram.errors import BadRequest, ChannelPrivate

from bot.config import api_id, api_hash

Expand Down Expand Up @@ -33,10 +33,13 @@ async def safe_get_channel(channel: str):
except KeyError as e:
if str(e).startswith("Username not found:"):
return GetChatStatus.USER_NOT_EXIST, None
raise e
except BadRequest as e:
if e.ID == "USERNAME_INVALID" or e.ID == "USERNAME_NOT_OCCUPIED":
return GetChatStatus.USER_NOT_EXIST, None
raise e
except ChannelPrivate:
return GetChatStatus.PRIVATE_CHAT, None


async def get_messages(channel: str, post_ids: List[int]) -> List[types.Message]:
Expand Down

0 comments on commit 09ab094

Please sign in to comment.