Handle cases where denied_permissions might be None

This commit is contained in:
Dan 2019-08-03 19:50:12 +02:00
parent 937987a361
commit 8a99f996ab

View File

@ -81,16 +81,17 @@ class ChatPermissions(Object):
@staticmethod
def _parse(denied_permissions: types.ChatBannedRights) -> "ChatPermissions":
return ChatPermissions(
can_send_messages=not denied_permissions.send_messages,
can_send_media_messages=not denied_permissions.send_media,
can_send_other_messages=(
not denied_permissions.send_stickers or not denied_permissions.send_gifs or
not denied_permissions.send_games or not denied_permissions.send_inline
),
can_add_web_page_previews=not denied_permissions.embed_links,
can_send_polls=not denied_permissions.send_polls,
can_change_info=not denied_permissions.change_info,
can_invite_users=not denied_permissions.invite_users,
can_pin_messages=not denied_permissions.pin_messages
)
if isinstance(denied_permissions, types.ChatBannedRights):
return ChatPermissions(
can_send_messages=not denied_permissions.send_messages,
can_send_media_messages=not denied_permissions.send_media,
can_send_other_messages=(
not denied_permissions.send_stickers or not denied_permissions.send_gifs or
not denied_permissions.send_games or not denied_permissions.send_inline
),
can_add_web_page_previews=not denied_permissions.embed_links,
can_send_polls=not denied_permissions.send_polls,
can_change_info=not denied_permissions.change_info,
can_invite_users=not denied_permissions.invite_users,
can_pin_messages=not denied_permissions.pin_messages
)