Browse Source

Add PremiumType enumeration and ClientUser.premium_type

pull/1894/head
Liam H 6 years ago
committed by Rapptz
parent
commit
79f172cf80
  1. 7
      discord/enums.py
  2. 7
      discord/user.py

7
discord/enums.py

@ -29,7 +29,8 @@ from enum import Enum, IntEnum
__all__ = ['ChannelType', 'MessageType', 'VoiceRegion', 'SpeakingState',
'VerificationLevel', 'ContentFilter', 'Status', 'DefaultAvatar',
'RelationshipType', 'AuditLogAction', 'AuditLogActionCategory',
'UserFlags', 'ActivityType', 'HypeSquadHouse', 'NotificationLevel']
'UserFlags', 'ActivityType', 'HypeSquadHouse', 'NotificationLevel',
'PremiumType']
class ChannelType(Enum):
text = 0
@ -245,6 +246,10 @@ class HypeSquadHouse(Enum):
brilliance = 2
balance = 3
class PremiumType(Enum):
nitro_classic = 1
nitro = 2
def try_enum(cls, val):
"""A function that tries to turn the value into enum ``cls``.

7
discord/user.py

@ -28,7 +28,7 @@ from collections import namedtuple
import discord.abc
from .utils import snowflake_time, _bytes_to_base64_data, parse_time, valid_icon_size
from .enums import DefaultAvatar, RelationshipType, UserFlags, HypeSquadHouse
from .enums import DefaultAvatar, RelationshipType, UserFlags, HypeSquadHouse, PremiumType, try_enum
from .errors import ClientException, InvalidArgument
from .colour import Colour
@ -299,8 +299,10 @@ class ClientUser(BaseUser):
Specifies if the user has MFA turned on and working.
premium: :class:`bool`
Specifies if the user is a premium user (e.g. has Discord Nitro).
premium_type: :class:`PremiumType`
Specifies the type of premium a user has (e.g. Nitro or Nitro Classic). Could be None if the user is not premium.
"""
__slots__ = ('email', 'verified', 'mfa_enabled', 'premium', '_relationships')
__slots__ = ('email', 'verified', 'mfa_enabled', 'premium', 'premium_type', '_relationships')
def __init__(self, *, state, data):
super().__init__(state=state, data=data)
@ -308,6 +310,7 @@ class ClientUser(BaseUser):
self.email = data.get('email')
self.mfa_enabled = data.get('mfa_enabled', False)
self.premium = data.get('premium', False)
self.premium_type = try_enum(PremiumType, data.get('premium_type', None))
self._relationships = {}
def __repr__(self):

Loading…
Cancel
Save