Browse Source

Inject state into PartialEmoji in Activity

pull/7632/head
Sebastian Law 3 years ago
committed by GitHub
parent
commit
483ffeacd4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      discord/activity.py
  2. 2
      discord/client.py
  3. 2
      discord/member.py
  4. 2
      discord/widget.py

19
discord/activity.py

@ -99,6 +99,8 @@ if TYPE_CHECKING:
ActivityButton, ActivityButton,
) )
from .state import ConnectionState
class BaseActivity: class BaseActivity:
"""The base activity that all user-settable activities inherit from. """The base activity that all user-settable activities inherit from.
@ -809,16 +811,16 @@ ActivityTypes = Union[Activity, Game, CustomActivity, Streaming, Spotify]
@overload @overload
def create_activity(data: ActivityPayload) -> ActivityTypes: def create_activity(data: ActivityPayload, state: ConnectionState) -> ActivityTypes:
... ...
@overload @overload
def create_activity(data: None) -> None: def create_activity(data: None, state: ConnectionState) -> None:
... ...
def create_activity(data: Optional[ActivityPayload]) -> Optional[ActivityTypes]: def create_activity(data: Optional[ActivityPayload], state: ConnectionState) -> Optional[ActivityTypes]:
if not data: if not data:
return None return None
@ -831,10 +833,10 @@ def create_activity(data: Optional[ActivityPayload]) -> Optional[ActivityTypes]:
try: try:
name = data.pop('name') name = data.pop('name')
except KeyError: except KeyError:
return Activity(**data) ret = Activity(**data)
else: else:
# we removed the name key from data already # we removed the name key from data already
return CustomActivity(name=name, **data) # type: ignore ret = CustomActivity(name=name, **data) # type: ignore
elif game_type is ActivityType.streaming: elif game_type is ActivityType.streaming:
if 'url' in data: if 'url' in data:
# the url won't be None here # the url won't be None here
@ -842,4 +844,9 @@ def create_activity(data: Optional[ActivityPayload]) -> Optional[ActivityTypes]:
return Activity(**data) return Activity(**data)
elif game_type is ActivityType.listening and 'sync_id' in data and 'session_id' in data: elif game_type is ActivityType.listening and 'sync_id' in data and 'session_id' in data:
return Spotify(**data) return Spotify(**data)
return Activity(**data) else:
ret = Activity(**data)
if isinstance(ret.emoji, PartialEmoji):
ret.emoji._state = state
return ret

2
discord/client.py

@ -717,7 +717,7 @@ class Client:
"""Optional[:class:`.BaseActivity`]: The activity being used upon """Optional[:class:`.BaseActivity`]: The activity being used upon
logging in. logging in.
""" """
return create_activity(self._connection._activity) return create_activity(self._connection._activity, self._connection)
@activity.setter @activity.setter
def activity(self, value: Optional[ActivityTypes]) -> None: def activity(self, value: Optional[ActivityTypes]) -> None:

2
discord/member.py

@ -448,7 +448,7 @@ class Member(discord.abc.Messageable, _UserTag):
self._avatar = data.get('avatar') self._avatar = data.get('avatar')
def _presence_update(self, data: PartialPresenceUpdate, user: UserPayload) -> Optional[Tuple[User, User]]: def _presence_update(self, data: PartialPresenceUpdate, user: UserPayload) -> Optional[Tuple[User, User]]:
self.activities = tuple(map(create_activity, data['activities'])) self.activities = tuple(create_activity(d, self._state) for d in data['activities'])
self._client_status._update(data['status'], data['client_status']) self._client_status._update(data['status'], data['client_status'])
if len(user) > 1: if len(user) > 1:

2
discord/widget.py

@ -188,7 +188,7 @@ class WidgetMember(BaseUser):
except KeyError: except KeyError:
activity = None activity = None
else: else:
activity = create_activity(game) activity = create_activity(game, state)
self.activity: Optional[Union[BaseActivity, Spotify]] = activity self.activity: Optional[Union[BaseActivity, Spotify]] = activity

Loading…
Cancel
Save