From 82a94cac7afe4bde895813d665986b197793426f Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Sun, 4 Jun 2023 13:21:23 +0300 Subject: [PATCH 1/4] fix && formation --- boticordpy/client.py | 2 +- boticordpy/types.py | 126 +++++++++++++++++++++---------------------- docs/source/conf.py | 8 ++- 3 files changed, 69 insertions(+), 67 deletions(-) diff --git a/boticordpy/client.py b/boticordpy/client.py index 1d8aaed..e353f2c 100644 --- a/boticordpy/client.py +++ b/boticordpy/client.py @@ -62,7 +62,7 @@ class BoticordClient: Bot's shards count users ( :obj:`int` ) Bot's users count - + Returns: :obj:`~.types.ResourceBot`: ResourceBot object. diff --git a/boticordpy/types.py b/boticordpy/types.py index c10a442..22a60fe 100644 --- a/boticordpy/types.py +++ b/boticordpy/types.py @@ -213,37 +213,37 @@ class BotLibrary(IntEnum): DISCORD4J = 1 """Discord4j""" - + DISCORDCR = 2 """Discordcr""" - + DISCORDGO = 3 """DiscordGO""" - + DISCORDDOO = 4 """Discordoo""" - + DSHARPPLUS = 5 """DSharpPlus""" - + DISCORDJS = 6 """Discord.js""" - + DISCORDNET = 7 """Discord.Net""" - + DISCORDPY = 8 """discord.py""" - + ERIS = 9 """eris""" - + JAVACORD = 10 """JavaCord""" - + JDA = 11 """JDA""" - + OTHER = 12 """Other""" @@ -409,7 +409,7 @@ class UserLinks(APIObjectBase): self.custon = data.get("custom") return self - + @dataclass(repr=False) class UserBadge(APIObjectBase): @@ -435,9 +435,9 @@ class UserBadge(APIObjectBase): """ self: UserBadge = super().__new__(cls) - self.id = data['id'] - self.name = data['name'] - self.asset_url = data['assetURL'] + self.id = data["id"] + self.name = data["name"] + self.asset_url = data["assetURL"] return self @@ -554,11 +554,6 @@ class PartialUser(APIObjectBase): self.short_domain = data.get("shortDomain") return self - - -@dataclass(repr=False) -class ResourceBot(APIObjectBase): - """Tak nado""" @dataclass(repr=False) @@ -639,24 +634,24 @@ class ResourceServer(APIObjectBase): ---------- data: :class:`dict` The dictionary to convert into a ResourceServer.""" - + self = super().__new__(cls) - self.id = data['id'] - self.name = data['name'] - self.short_description = data['shortDescription'] - self.description = data['description)'] + self.id = data["id"] + self.name = data["name"] + self.short_description = data["shortDescription"] + self.description = data["description)"] self.avatar = data.get("avatar") self.short_link = data.get("shortLink") self.invite_link = data.get("inviteLink") self.owner = data.get("owner") self.website = data.get("website") self.up_count = data.get("upCount") - - self.premium_active = data['premium'].get('active') - self.premium_splash_url = data['premium'].get('splashURL') - self.premium_auto_fetch = data['premium'].get('autoFetch') - self.premium_banner_url = data['premium'].get('bannerURL') + + self.premium_active = data["premium"].get("active") + self.premium_splash_url = data["premium"].get("splashURL") + self.premium_auto_fetch = data["premium"].get("autoFetch") + self.premium_banner_url = data["premium"].get("bannerURL") self.status = ResourceStatus(data.get("status")) self.ratings = [ @@ -676,46 +671,14 @@ class ResourceServer(APIObjectBase): return self -@dataclass(repr=False) -class UserProfile(PartialUser): - """Information about user's profile from BotiCord. - - It has all from PartialUser and some more params: 'bots', 'servers', 'badges'""" - - badges: List[UserBadge] - """User's badges list.""" - - bots: List[ResourceBot] - """User's bots list""" - - servers: List[ResourceServer] - """User's servers list""" - - @classmethod - def from_dict(cls, data: dict): - """Generate a UserProfile from the given data. - - Parameters - ---------- - data: :class:`dict` - The dictionary to convert into a UserProfile.""" - - self = super().from_dict(data) - - self.badges = [UserBadge.from_dict(badge) for badge in data.get('badges', [])] - self.bots = [ResourceBot.from_dict(bot) for bot in data.get('bots', [])] - self.servers = [ResourceServer.from_dict(server) for server in data.get('servers', [])] - - return self - - @dataclass(repr=False) class ResourceBot(APIObjectBase): """Bot published on BotiCord .. warning:: - The result of the reverse conversion (`.to_dict()`) may not match the actual data.""" + The result of the reverse conversion (`.to_dict()`) may not match the actual data. + """ id: str """ID of the bot""" @@ -852,5 +815,40 @@ class ResourceBot(APIObjectBase): return self +@dataclass(repr=False) +class UserProfile(PartialUser): + """Information about user's profile from BotiCord. + + It has all from PartialUser and some more params: 'bots', 'servers', 'badges'""" + + badges: List[UserBadge] + """User's badges list.""" + + bots: List[ResourceBot] + """User's bots list""" + + servers: List[ResourceServer] + """User's servers list""" + + @classmethod + def from_dict(cls, data: dict): + """Generate a UserProfile from the given data. + + Parameters + ---------- + data: :class:`dict` + The dictionary to convert into a UserProfile.""" + + self = super().from_dict(data) + + self.badges = [UserBadge.from_dict(badge) for badge in data.get("badges", [])] + self.bots = [ResourceBot.from_dict(bot) for bot in data.get("bots", [])] + self.servers = [ + ResourceServer.from_dict(server) for server in data.get("servers", []) + ] + + return self + + class LinkDomain: pass diff --git a/docs/source/conf.py b/docs/source/conf.py index 961f62b..88ac24a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -42,10 +42,14 @@ extensions = [ "sphinx.ext.viewcode", "sphinx.ext.autosectionlabel", "sphinx.ext.extlinks", - "sphinxcontrib_trio" + "sphinxcontrib_trio", ] -autodoc_default_options = {"members": True, "show-inheritance": True, 'member-order': 'bysource'} +autodoc_default_options = { + "members": True, + "show-inheritance": True, + "member-order": "bysource", +} # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] From fbef6fe29abf2c9c64ab26598a77cfff73bfdc05 Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Sun, 4 Jun 2023 13:32:13 +0300 Subject: [PATCH 2/4] fixes && get_server_info() method --- LICENSE.txt | 2 +- boticordpy/client.py | 18 +++++++++++++++++- boticordpy/http.py | 11 +---------- boticordpy/types.py | 10 +++++----- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 7ab55d1..df4f53d 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2021 Victor Kotlin +Copyright 2021 - 2023 Viktor K Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/boticordpy/client.py b/boticordpy/client.py index e353f2c..55ad05f 100644 --- a/boticordpy/client.py +++ b/boticordpy/client.py @@ -43,7 +43,7 @@ class BoticordClient: response = await self.http.get_bot_info(bot_id) return boticord_types.ResourceBot.from_dict(response) - async def post_bot_stats( + async def get_server_info( self, bot_id: typing.Union[str, int], *, @@ -72,6 +72,22 @@ class BoticordClient: ) return boticord_types.ResourceBot.from_dict(response) + async def get_server_info( + self, server_id: typing.Union[str, int] + ) -> boticord_types.ResourceServer: + """Gets information about specified server. + + Args: + server_id (Union[:obj:`str`, :obj:`int`]) + Id of the server + + Returns: + :obj:`~.types.ResourceServer`: + ResourceServer object. + """ + response = await self.http.get_server_info(server_id) + return boticord_types.ResourceServer.from_dict(response) + def autopost(self) -> AutoPost: """Returns a helper instance for auto-posting. diff --git a/boticordpy/http.py b/boticordpy/http.py index 77c82cc..55eda40 100644 --- a/boticordpy/http.py +++ b/boticordpy/http.py @@ -57,15 +57,6 @@ class HttpClient: """Post bot's stats""" return self.make_request("POST", f"bots/{bot_id}/stats", json=stats) - def get_server_info(self, server_id: int): + def get_server_info(self, server_id: typing.Union[str, int]): """Get information about specified server""" return self.make_request("GET", f"servers/{server_id}") - - # TODO - def get_server_comments(self, server_id: int): - """Get list of specified server comments""" - return self.make_request("GET", f"server/{server_id}/comments") - - def get_user_info(self, user_id: int): - """Get information about the user""" - return self.make_request("GET", f"users/{user_id}") diff --git a/boticordpy/types.py b/boticordpy/types.py index 22a60fe..66667d3 100644 --- a/boticordpy/types.py +++ b/boticordpy/types.py @@ -637,10 +637,10 @@ class ResourceServer(APIObjectBase): self = super().__new__(cls) - self.id = data["id"] - self.name = data["name"] - self.short_description = data["shortDescription"] - self.description = data["description)"] + self.id = data.get("id") + self.name = data.get("name") + self.short_description = data.get("shortDescription") + self.description = data.get("description") self.avatar = data.get("avatar") self.short_link = data.get("shortLink") self.invite_link = data.get("inviteLink") @@ -658,7 +658,7 @@ class ResourceServer(APIObjectBase): ResourceRating.from_dict(rating) for rating in data.get("ratings", []) ] self.created_date = datetime.strptime( - data["createdDate"], "%Y-%m-%dT%H:%M:%S.%f%z" + data.get("createdDate"), "%Y-%m-%dT%H:%M:%S.%f%z" ) self.tags = [ServerTag(tag) for tag in data.get("tags", [])] self.ups = [ResourceUp.from_dict(up) for up in data.get("ups", [])] From 324b70dd2eff458729acfa88938862478de41be1 Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Sun, 4 Jun 2023 13:40:59 +0300 Subject: [PATCH 3/4] better docs for exceptions, UserProfile --- boticordpy/types.py | 4 +--- docs/source/api/exceptions.rst | 17 +++++++++++++++-- docs/source/api/types.rst | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/boticordpy/types.py b/boticordpy/types.py index 66667d3..4d455c9 100644 --- a/boticordpy/types.py +++ b/boticordpy/types.py @@ -817,9 +817,7 @@ class ResourceBot(APIObjectBase): @dataclass(repr=False) class UserProfile(PartialUser): - """Information about user's profile from BotiCord. - - It has all from PartialUser and some more params: 'bots', 'servers', 'badges'""" + """Information about user's profile from BotiCord.'""" badges: List[UserBadge] """User's badges list.""" diff --git a/docs/source/api/exceptions.rst b/docs/source/api/exceptions.rst index 92ffe2c..1767b4a 100644 --- a/docs/source/api/exceptions.rst +++ b/docs/source/api/exceptions.rst @@ -1,7 +1,20 @@ +.. currentmodule:: boticordpy.exceptions + ########################## Exceptions API Reference ########################## -.. automodule:: boticordpy.exceptions +.. autoclass:: BoticordException + :members: + +.. autoclass:: InternalException + :members: + +.. autoclass:: HTTPException + :members: + +.. autoclass:: StatusCodes + :members: + +.. autoclass:: HTTPErrors :members: - :inherited-members: diff --git a/docs/source/api/types.rst b/docs/source/api/types.rst index c7cb70b..90945e4 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/types.rst @@ -51,3 +51,5 @@ Users .. autoclass:: UserProfile :members: + :exclude-members: to_dict + :inherited-members: From 1c9de56267947c761f002040988263d3e973d446 Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Sun, 4 Jun 2023 13:42:18 +0300 Subject: [PATCH 4/4] added UserBadge to docs --- docs/source/api/types.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/source/api/types.rst b/docs/source/api/types.rst index 90945e4..675d748 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/types.rst @@ -46,6 +46,9 @@ Users .. autoclass:: UserLinks :members: +.. autoclass:: UserBadge + :members: + .. autoclass:: PartialUser :members: