Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unusual_dm_activity_until field on member #9809

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions discord/member.py
Original file line number Diff line number Diff line change
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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like this method name, not a fan of has_ methods unless it's a last resort kind of thing.

"""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
Loading