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,
)
from .state import ConnectionState
class BaseActivity:
"""The base activity that all user-settable activities inherit from.
@ -809,16 +811,16 @@ ActivityTypes = Union[Activity, Game, CustomActivity, Streaming, Spotify]
@overload
def create_activity(data: ActivityPayload) -> ActivityTypes:
def create_activity(data: ActivityPayload, state: ConnectionState) -> ActivityTypes:
...
@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:
return None
@ -831,10 +833,10 @@ def create_activity(data: Optional[ActivityPayload]) -> Optional[ActivityTypes]:
try:
name = data.pop('name')
except KeyError:
return Activity(**data)
ret = Activity(**data)
else:
# 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:
if 'url' in data:
# the url won't be None here
@ -842,4 +844,9 @@ def create_activity(data: Optional[ActivityPayload]) -> Optional[ActivityTypes]:
return Activity(**data)
elif game_type is ActivityType.listening and 'sync_id' in data and 'session_id' in 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
logging in.
"""
return create_activity(self._connection._activity)
return create_activity(self._connection._activity, self._connection)
@activity.setter
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')
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'])
if len(user) > 1:

2
discord/widget.py

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

Loading…
Cancel
Save