Browse Source

Properly implement FriendSuggestionReason

pull/10109/head
dolfies 2 years ago
parent
commit
178eb31cf2
  1. 5
      discord/enums.py
  2. 12
      discord/relationship.py
  3. 4
      discord/types/user.py
  4. 10
      docs/api.rst

5
discord/enums.py

@ -69,6 +69,7 @@ __all__ = (
'ApplicationCommandOptionType',
'AppCommandOptionType',
'RelationshipType',
'FriendSuggestionReasonType',
'HypeSquadHouse',
'PremiumType',
'UserContentFilter',
@ -445,6 +446,10 @@ class RelationshipType(Enum):
suggestion = 6 # Unused
class FriendSuggestionReasonType(Enum):
external_friend = 1
class NotificationLevel(Enum, comparable=True):
all_messages = 0
all = 0

12
discord/relationship.py

@ -26,7 +26,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Optional, Tuple, Union
from .enums import ConnectionType, RelationshipAction, RelationshipType, Status, try_enum
from .enums import ConnectionType, FriendSuggestionReasonType, RelationshipAction, RelationshipType, Status, try_enum
from .mixins import Hashable
from .object import Object
from .utils import MISSING, parse_time
@ -336,20 +336,22 @@ class FriendSuggestionReason:
Attributes
-----------
type: :class:`FriendSuggestionReasonType`
The type of friend suggestion reason.
platform: :class:`ConnectionType`
The platform the user was suggested from.
name: Optional[:class:`str`]
name: :class:`str`
The user's name on the platform.
"""
__slots__ = ('type', 'platform', 'name')
def __init__(self, data: FriendSuggestionReasonPayload):
# This entire model is mostly unused by any client, so I have no idea what the type is
# This entire model is mostly unused by any client, so I can't be sure on types
# Also because of this, I'm treating everything as optional just in case
self.type: int = data.get('type', 0)
self.type: FriendSuggestionReasonType = try_enum(FriendSuggestionReasonType, data.get('type', 0))
self.platform: ConnectionType = try_enum(ConnectionType, data.get('platform'))
self.name: Optional[str] = data.get('name')
self.name: str = data.get('name') or ''
def __repr__(self) -> str:
return f'<FriendSuggestionReason platform={self.platform!r} name={self.name!r}>'

4
discord/types/user.py

@ -160,9 +160,9 @@ class Note(TypedDict):
class FriendSuggestionReason(TypedDict):
name: Optional[str]
name: str
platform_type: ConnectionType
type: int
type: Literal[1]
class FriendSuggestion(TypedDict):

10
docs/api.rst

@ -3787,6 +3787,16 @@ of :class:`enum.Enum`.
.. versionadded:: 2.0
.. class:: FriendSuggestionReasonType
Specifies the type of :class:`FriendSuggestionReason`.
.. versionadded:: 2.1
.. attribute:: external_friend
You are friends with this user on another platform.
.. class:: UserContentFilter
Represents the options found in ``Settings > Privacy & Safety > Safe Direct Messaging``

Loading…
Cancel
Save