Skip to content

Commit

Permalink
Fix usage in channels
Browse files Browse the repository at this point in the history
  • Loading branch information
ebellocchia committed May 16, 2023
1 parent 08c5e0e commit 15bac0f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions telegram_periodic_msg_bot/command/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,19 @@ 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 self._IsChannel():
return True

# Anonymous user
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
# Private chat is always authorized
if ChatHelper.IsPrivateChat(self.cmd_data.Chat(), cmd_user):
return True

# Check if admin
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))

Expand Down

0 comments on commit 15bac0f

Please sign in to comment.