Skip to content

Commit

Permalink
Add support for unusual_dm_activity_until field
Browse files Browse the repository at this point in the history
  • Loading branch information
Soheab committed Apr 27, 2024
1 parent 8fd1fd8 commit 3ed5c20
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions discord/member.py
Expand Up @@ -306,6 +306,11 @@ class Member(discord.abc.Messageable, _UserTag):
This will be set to ``None`` if the user is not timed out.
.. versionadded:: 2.0
unusual_dm_activity_until: Optional[:class:`datetime.datetime`]
An aware datetime object that specifies the date and time in UTC that the member's unusual DM activity will expire.
This will be set to ``None`` if the user does not have unusual DM activity.
.. versionadded:: 2.4
"""

__slots__ = (
Expand All @@ -324,6 +329,7 @@ class Member(discord.abc.Messageable, _UserTag):
'_avatar',
'_flags',
'_avatar_decoration_data',
'unusual_dm_activity_until',
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -367,6 +373,7 @@ def __init__(self, *, data: MemberWithUserPayload, guild: Guild, state: Connecti
self._permissions = None

self.timed_out_until: Optional[datetime.datetime] = utils.parse_time(data.get('communication_disabled_until'))
self.unusual_dm_activity_until: Optional[datetime.datetime] = utils.parse_time(data.get('unusual_dm_activity_until'))

def __str__(self) -> str:
return str(self._user)
Expand Down Expand Up @@ -400,6 +407,7 @@ def _update_from_message(self, data: MemberPayload) -> None:
self.pending = data.get('pending', False)
self.timed_out_until = utils.parse_time(data.get('communication_disabled_until'))
self._flags = data.get('flags', 0)
self.unusual_dm_activity_until = utils.parse_time(data.get('unusual_dm_activity_until'))

@classmethod
def _try_upgrade(cls, *, data: UserWithMemberPayload, guild: Guild, state: ConnectionState) -> Union[User, Self]:
Expand Down Expand Up @@ -430,6 +438,7 @@ def _copy(cls, member: Self) -> Self:
self._state = member._state
self._avatar = member._avatar
self._avatar_decoration_data = member._avatar_decoration_data
self.unusual_dm_activity_until = member.unusual_dm_activity_until

# Reference will not be copied unless necessary by PRESENCE_UPDATE
# See below
Expand Down Expand Up @@ -459,6 +468,7 @@ def _update(self, data: GuildMemberUpdateEvent) -> None:
self._avatar = data.get('avatar')
self._flags = data.get('flags', 0)
self._avatar_decoration_data = data.get('avatar_decoration_data')
self.unusual_dm_activity_until = utils.parse_time(data.get('unusual_dm_activity_until'))

def _presence_update(self, data: PartialPresenceUpdate, user: UserPayload) -> Optional[Tuple[User, User]]:
self.activities = tuple(create_activity(d, self._state) for d in data['activities'])
Expand Down Expand Up @@ -1148,3 +1158,17 @@ def is_timed_out(self) -> bool:
if self.timed_out_until is not None:
return utils.utcnow() < self.timed_out_until
return False

def has_unusual_dm_activity(self) -> bool:
"""Returns whether this member has unusual DM activity.
.. versionadded:: 2.4
Returns
--------
:class:`bool`
``True`` if the member has unusual DM activity. ``False`` otherwise.
"""
if self.unusual_dm_activity_until is not None:
return utils.utcnow() < self.unusual_dm_activity_until
return False

0 comments on commit 3ed5c20

Please sign in to comment.