Skip to content

classes

Friend

Represents a friend of a Luduvo user.

Attributes:

Name Type Description
id int

The friend's user ID.

username str

The friend's username.

Source code in luduvo/utilities/classes.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class Friend:
    """
    Represents a friend of a Luduvo user.

    Attributes:
        id: The friend's user ID.
        username: The friend's username.
    """

    def __init__(self, __client__, **data):
        self.id: int = data["user_id"]
        self.username: str = data["username"]
        self.__client__ = __client__

    def __repr__(self):
        return f"<Friend id={self.id} username={self.username}>"

PartialUser

Represents a partial Luduvo user, containing only basic information.

Attributes:

Name Type Description
id int

The user's ID.

username str

The user's username.

display_name str

The user's display name.

created_at datetime

The datetime the user joined Luduvo.

Source code in luduvo/utilities/classes.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class PartialUser:
    """
    Represents a partial Luduvo user, containing only basic information.

    Attributes:
        id: The user's ID.
        username: The user's username.
        display_name: The user's display name.
        created_at: The datetime the user joined Luduvo.
    """

    def __init__(self, client, data):
        self.id: int = data.get("id")
        self.username: str = data.get("username")
        self.display_name: str = data.get("display_name")
        self.created_at: datetime.datetime = datetime.datetime.fromtimestamp(
            data.get("created_at")
        )
        self.__client__ = client

    def __repr__(self):
        return f"<PartialUser id={self.id} username={self.username}>"

User

Represents a Luduvo user.

Attributes:

Name Type Description
id int

The user's ID.

username str

The user's username.

created_at datetime

The datetime the user joined Luduvo.

display_name str

The user's display name.

status str

The user's status message.

bio str

The user's biography.

avatar dict

A dictionary containing information about the user's avatar.

equipped_items list

A list of items currently equipped by the user.

badges list

A list of badges owned by the user.

friend_count int

The number of friends the user has.

place_count int

The number of places owned by the user.

item_count int

The number of items owned by the user.

last_active
allow_joins bool

Whether the user allows others to join their games.

Source code in luduvo/utilities/classes.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class User:
    """
    Represents a Luduvo user.

    Attributes:
        id: The user's ID.
        username: The user's username.
        created_at: The datetime the user joined Luduvo.
        display_name: The user's display name.
        status: The user's status message.
        bio: The user's biography.
        avatar: A dictionary containing information about the user's avatar.
        equipped_items: A list of items currently equipped by the user.
        badges: A list of badges owned by the user.
        friend_count: The number of friends the user has.
        place_count: The number of places owned by the user.
        item_count: The number of items owned by the user.
        last_active:
        allow_joins: Whether the user allows others to join their games.
    """

    def __init__(self, client, data):
        self.id: int = data.get("user_id")
        self.username: str = data.get("username")
        self.created_at: datetime.datetime = datetime.datetime.fromtimestamp(
            data.get("member_since")
        )
        self.display_name: str = data.get("display_name")
        self.status: str = data.get("status")
        self.bio: str = data.get("bio")
        self.avatar: dict = data.get("avatar")
        self.equipped_items: list = data.get("equipped_items")
        self.badges: list = data.get("badges")
        self.friend_count: int = data.get("friend_count")
        self.place_count: int = data.get("place_count")
        self.item_count: int = data.get("item_count")
        self.last_active = data.get("last_active")
        self.allow_joins: bool = data.get("allow_joins")
        self.__client__ = client

    def __repr__(self):
        return f"<User id={self.id} username={self.username}>"

    async def get_friends(self, limit: int = 50) -> list[Friend]:
        """Gets the user's friends.

        Args:
            limit (int, optional): The maximum number of friends to retrieve. Defaults to 50.

        Returns:
            list[Friend]: A list of the user's friends.
        """
        offset = 0
        friends: list[Friend] = []

        while True:
            response = await self.__client__._requests.get(
                url=self.__client__.url_generator.get_url(
                    f"users/{self.id}/friends", "api"
                ),
                params={"limit": limit, "offset": offset},
            )

            data = response.json()

            page_friends = [
                Friend(__client__=self.__client__, **f) for f in data["friends"]
            ]

            friends.extend(page_friends)

            offset += limit

            if offset >= data["total"] or not page_friends:
                break

        return friends

get_friends(limit=50) async

Gets the user's friends.

Parameters:

Name Type Description Default
limit int

The maximum number of friends to retrieve. Defaults to 50.

50

Returns:

Type Description
list[Friend]

list[Friend]: A list of the user's friends.

Source code in luduvo/utilities/classes.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
async def get_friends(self, limit: int = 50) -> list[Friend]:
    """Gets the user's friends.

    Args:
        limit (int, optional): The maximum number of friends to retrieve. Defaults to 50.

    Returns:
        list[Friend]: A list of the user's friends.
    """
    offset = 0
    friends: list[Friend] = []

    while True:
        response = await self.__client__._requests.get(
            url=self.__client__.url_generator.get_url(
                f"users/{self.id}/friends", "api"
            ),
            params={"limit": limit, "offset": offset},
        )

        data = response.json()

        page_friends = [
            Friend(__client__=self.__client__, **f) for f in data["friends"]
        ]

        friends.extend(page_friends)

        offset += limit

        if offset >= data["total"] or not page_friends:
            break

    return friends