| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,8 +10,17 @@ | |||
| 10 | 10 | from .types import User as UserPayload, UserRelation | |
| 11 | 11 | ||
| 12 | 12 | 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 | + """ | ||
| 13 | 22 | type: RelationshipType | |
| 14 | - user: Optional["User"] | ||
| 23 | + user: User | ||
| 15 | 24 | ||
| 16 | 25 | class Status(NamedTuple): | |
| 17 | 26 | text: Optional[str] | |
@@ -38,6 +47,12 @@ class User: | |||
| 38 | 47 | The user flags | |
| 39 | 48 | avatar: :class:`Asset` | |
| 40 | 49 | 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 | ||
| 41 | 56 | """ | |
| 42 | 57 | __flattern_attributes__ = ("id", "name", "bot", "owner", "badges", "online", "flags") | |
| 43 | 58 | ||
@@ -61,7 +76,14 @@ def __init__(self, data: UserPayload, state: State): | |||
| 61 | 76 | avatar = data.get("avatar") | |
| 62 | 77 | self.avatar = Asset(avatar, state) if avatar else None | |
| 63 | 78 | ||
| 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 | + | ||
| 65 | 87 | relationship = data.get("relationship") | |
| 66 | 88 | self.relationship = RelationshipType(relationship) if relationship else None | |
| 67 | 89 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments