Skip to content

Commit

Permalink
Remove optional parameter from IsPrivateChat
Browse files Browse the repository at this point in the history
  • Loading branch information
ebellocchia committed Sep 28, 2022
1 parent 6f0cff3 commit b377391
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions telegram_crypto_price_bot/command/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,25 @@ def _IsUserAnonymous(self) -> bool:

# Get if user is authorized
def _IsUserAuthorized(self) -> bool:
# In channels only admins can write, so we consider the user authorized since there is no way to know the specific user
# This is a limitation for channels only
if ChatHelper.IsPrivateChat(self.cmd_data.Chat(), self.cmd_data.User()):
return True

cmd_user = self.cmd_data.User()
if cmd_user is None:
return False

# In channels only admins can write, so we consider the user authorized since there is no way to know the specific user
# This is a limitation for channels only
if ChatHelper.IsPrivateChat(self.cmd_data.Chat(), cmd_user):
return True

admin_members = ChatMembersGetter(self.client).GetAdmins(self.cmd_data.Chat())
return any((cmd_user.id == member.user.id for member in admin_members if member.user is not None))

# Get if chat is private
def _IsPrivateChat(self) -> bool:
if self._IsChannel():
cmd_user = self.cmd_data.User()
if self._IsChannel() or cmd_user is None:
return False
return ChatHelper.IsPrivateChat(self.cmd_data.Chat(), self.cmd_data.User())
return ChatHelper.IsPrivateChat(self.cmd_data.Chat(), cmd_user)


# Log command
def __LogCommand(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion telegram_crypto_price_bot/misc/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def GetTitleOrId(chat: pyrogram.types.Chat) -> str:
# Get if private chat
@staticmethod
def IsPrivateChat(chat: pyrogram.types.Chat,
user: Optional[pyrogram.types.User]):
user: pyrogram.types.User):
if ChatHelper.IsChannel(chat) or user is None:
return False
return chat.id == user.id
Expand Down

0 comments on commit b377391

Please sign in to comment.