FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix user relations · stoatchat/python-client-sdk@3a7e7b3 · GitHub

Commit 3a7e7b3

Browse files
committed
fix user relations
1 parent 37e3da5 commit 3a7e7b3

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

‎revolt/user.py‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@
1010
from .types import User as UserPayload, UserRelation
1111

1212
class Relation(NamedTuple):
13+
"""A namedtuple representing a relation between the bot and a user
14+
15+
Attributes
16+
-----------
17+
type: :class:`RelationshipType`
18+
The type of relationship
19+
user: :class:`User`
20+
The user the relationship is for
21+
"""
1322
type: RelationshipType
14-
user: Optional["User"]
23+
user: User
1524

1625
class Status(NamedTuple):
1726
text: Optional[str]
@@ -38,6 +47,12 @@ class User:
3847
The user flags
3948
avatar: :class:`Asset`
4049
The users avatar if they have one
50+
relations: list[:class:`Relation`]
51+
A list of the users relations
52+
relationship: Optional[:class:`RelationshipType`]
53+
The relationship between the user and the bot
54+
status: Optional[:class:`Status`]
55+
The users status
4156
"""
4257
__flattern_attributes__ = ("id", "name", "bot", "owner", "badges", "online", "flags")
4358

@@ -61,7 +76,14 @@ def __init__(self, data: UserPayload, state: State):
6176
avatar = data.get("avatar")
6277
self.avatar = Asset(avatar, state) if avatar else None
6378

64-
self.relations = [Relation(RelationshipType(relation["status"]), state.get_user(relation["_id"])) for relation in data.get("relations", [])]
79+
relations = []
80+
81+
for relation in data.get("relations", []):
82+
user = state.get_user(relation["_id"])
83+
if user:
84+
relations.append(Relation(RelationshipType(relation["status"]), user))
85+
self.relations = relations
86+
6587
relationship = data.get("relationship")
6688
self.relationship = RelationshipType(relationship) if relationship else None
6789

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL