11import time
2+ from enum import IntEnum
23
4+ from ..models import StatusType
35from .misc import DictSerializerMixin , Snowflake
46
57
@@ -77,12 +79,29 @@ def __init__(self, **kwargs):
7779 super ().__init__ (** kwargs )
7880
7981
82+ class PresenceActivityType (IntEnum ):
83+ """
84+ A class object representing all supported Discord activity types.
85+ """
86+
87+ GAME = 0
88+ STREAMING = 1
89+ LISTENING = 2
90+ WATCHING = 3
91+ CUSTOM = 4
92+ COMPETING = 5
93+
94+
8095class PresenceActivity (DictSerializerMixin ):
8196 """
8297 A class object representing the current activity data of a presence.
8398
99+ .. note::
100+ When using this model to instantiate alongside the client, if you provide a type 1 ( or PresenceActivityType.STREAMING ), then
101+ the ``url`` attribute is necessary.
102+
84103 :ivar str name: The activity name
85- :ivar str type: The activity type
104+ :ivar Union[int, PresenceActivityType] type: The activity type
86105 :ivar Optional[str] url?: stream url (if type is 1)
87106 :ivar Snowflake created_at: Unix timestamp of when the activity was created to the User's session
88107 :ivar Optional[PresenceTimestamp] timestamps?: Unix timestamps for start and/or end of the game
@@ -128,6 +147,9 @@ class PresenceActivity(DictSerializerMixin):
128147
129148 def __init__ (self , ** kwargs ):
130149 super ().__init__ (** kwargs )
150+ self ._json ["type" ] = (
151+ self .type .value if isinstance (self .type , PresenceActivityType ) else self .type
152+ )
131153 self .application_id = (
132154 Snowflake (self .application_id ) if self ._json .get ("application_id" ) else None
133155 )
@@ -143,24 +165,43 @@ def __init__(self, **kwargs):
143165 self .assets = PresenceAssets (** self .assets ) if self ._json .get ("assets" ) else None
144166 self .secrets = PresenceSecrets (** self .secrets ) if self ._json .get ("secrets" ) else None
145167
168+ @property
169+ def gateway_json (self ) -> dict :
170+ """
171+ This returns the JSON representing the ClientPresence sending via the Gateway.
172+
173+ .. note::
174+ This is NOT used for standard presence activity reading by other users, i.e. User activity reading.
175+ You can use the `_json` attribute instead.
176+ """
177+ res = {"name" : self .name , "type" : self .type }
178+ if self .url :
179+ res ["url" ] = self .url
180+ return res
181+
146182
147183class ClientPresence (DictSerializerMixin ):
148184 """
149185 An object that symbolizes the presence of the current client's session upon creation.
150186
151187 :ivar Optional[int] since?: Unix time in milliseconds of when the client went idle. None if it is not idle.
152188 :ivar Optional[List[PresenceActivity]] activities: Array of activity objects.
153- :ivar str status: The client's new status.
189+ :ivar Union[ str, StatusType] status: The client's new status.
154190 :ivar bool afk: Whether the client is afk or not.
155191 """
156192
157193 __slots__ = ("_json" , "since" , "activities" , "status" , "afk" )
158194
159195 def __init__ (self , ** kwargs ):
160196 super ().__init__ (** kwargs )
197+ self ._json ["status" ] = (
198+ self .status .value if isinstance (self .status , StatusType ) else self .status
199+ )
161200 self .activities = (
162201 [
163- PresenceActivity (** (activity if isinstance (activity , dict ) else activity ._json ))
202+ PresenceActivity (
203+ ** (activity if isinstance (activity , dict ) else activity .gateway_json )
204+ )
164205 for activity in self ._json .get ("activities" )
165206 ]
166207 if self ._json .get ("activities" )
@@ -172,3 +213,5 @@ def __init__(self, **kwargs):
172213 # If since is not provided by the developer...
173214 self .since = int (time .time () * 1000 )
174215 self ._json ["since" ] = self .since
216+ if not self ._json .get ("afk" ):
217+ self ._json ["afk" ] = False
0 commit comments