Merge branch 'boticord:v3' into v3

This commit is contained in:
Mad Cat 2023-06-04 13:43:50 +03:00 committed by GitHub
commit 64a6548740
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 107 additions and 82 deletions

View file

@ -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: 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:

View file

@ -43,7 +43,7 @@ class BoticordClient:
response = await self.http.get_bot_info(bot_id) response = await self.http.get_bot_info(bot_id)
return boticord_types.ResourceBot.from_dict(response) return boticord_types.ResourceBot.from_dict(response)
async def post_bot_stats( async def get_server_info(
self, self,
bot_id: typing.Union[str, int], bot_id: typing.Union[str, int],
*, *,
@ -72,6 +72,22 @@ class BoticordClient:
) )
return boticord_types.ResourceBot.from_dict(response) 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: def autopost(self) -> AutoPost:
"""Returns a helper instance for auto-posting. """Returns a helper instance for auto-posting.

View file

@ -57,15 +57,6 @@ class HttpClient:
"""Post bot's stats""" """Post bot's stats"""
return self.make_request("POST", f"bots/{bot_id}/stats", json=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""" """Get information about specified server"""
return self.make_request("GET", f"servers/{server_id}") 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}")

View file

@ -435,9 +435,9 @@ class UserBadge(APIObjectBase):
""" """
self: UserBadge = super().__new__(cls) self: UserBadge = super().__new__(cls)
self.id = data['id'] self.id = data["id"]
self.name = data['name'] self.name = data["name"]
self.asset_url = data['assetURL'] self.asset_url = data["assetURL"]
return self return self
@ -556,11 +556,6 @@ class PartialUser(APIObjectBase):
return self return self
@dataclass(repr=False)
class ResourceBot(APIObjectBase):
"""Tak nado"""
@dataclass(repr=False) @dataclass(repr=False)
class ResourceServer(APIObjectBase): class ResourceServer(APIObjectBase):
"""Information about server from BotiCord.""" """Information about server from BotiCord."""
@ -642,10 +637,10 @@ class ResourceServer(APIObjectBase):
self = super().__new__(cls) self = super().__new__(cls)
self.id = data['id'] self.id = data.get("id")
self.name = data['name'] self.name = data.get("name")
self.short_description = data['shortDescription'] self.short_description = data.get("shortDescription")
self.description = data['description)'] self.description = data.get("description")
self.avatar = data.get("avatar") self.avatar = data.get("avatar")
self.short_link = data.get("shortLink") self.short_link = data.get("shortLink")
self.invite_link = data.get("inviteLink") self.invite_link = data.get("inviteLink")
@ -653,17 +648,17 @@ class ResourceServer(APIObjectBase):
self.website = data.get("website") self.website = data.get("website")
self.up_count = data.get("upCount") self.up_count = data.get("upCount")
self.premium_active = data['premium'].get('active') self.premium_active = data["premium"].get("active")
self.premium_splash_url = data['premium'].get('splashURL') self.premium_splash_url = data["premium"].get("splashURL")
self.premium_auto_fetch = data['premium'].get('autoFetch') self.premium_auto_fetch = data["premium"].get("autoFetch")
self.premium_banner_url = data['premium'].get('bannerURL') self.premium_banner_url = data["premium"].get("bannerURL")
self.status = ResourceStatus(data.get("status")) self.status = ResourceStatus(data.get("status"))
self.ratings = [ self.ratings = [
ResourceRating.from_dict(rating) for rating in data.get("ratings", []) ResourceRating.from_dict(rating) for rating in data.get("ratings", [])
] ]
self.created_date = datetime.strptime( 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.tags = [ServerTag(tag) for tag in data.get("tags", [])]
self.ups = [ResourceUp.from_dict(up) for up in data.get("ups", [])] self.ups = [ResourceUp.from_dict(up) for up in data.get("ups", [])]
@ -676,46 +671,14 @@ class ResourceServer(APIObjectBase):
return self 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) @dataclass(repr=False)
class ResourceBot(APIObjectBase): class ResourceBot(APIObjectBase):
"""Bot published on BotiCord """Bot published on BotiCord
.. warning:: .. 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: str
"""ID of the bot""" """ID of the bot"""
@ -852,5 +815,38 @@ class ResourceBot(APIObjectBase):
return self return self
@dataclass(repr=False)
class UserProfile(PartialUser):
"""Information about user's profile from BotiCord.'"""
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: class LinkDomain:
pass pass

View file

@ -1,7 +1,20 @@
.. currentmodule:: boticordpy.exceptions
########################## ##########################
Exceptions API Reference Exceptions API Reference
########################## ##########################
.. automodule:: boticordpy.exceptions .. autoclass:: BoticordException
:members:
.. autoclass:: InternalException
:members:
.. autoclass:: HTTPException
:members:
.. autoclass:: StatusCodes
:members:
.. autoclass:: HTTPErrors
:members: :members:
:inherited-members:

View file

@ -46,8 +46,13 @@ Users
.. autoclass:: UserLinks .. autoclass:: UserLinks
:members: :members:
.. autoclass:: UserBadge
:members:
.. autoclass:: PartialUser .. autoclass:: PartialUser
:members: :members:
.. autoclass:: UserProfile .. autoclass:: UserProfile
:members: :members:
:exclude-members: to_dict
:inherited-members:

View file

@ -42,10 +42,14 @@ extensions = [
"sphinx.ext.viewcode", "sphinx.ext.viewcode",
"sphinx.ext.autosectionlabel", "sphinx.ext.autosectionlabel",
"sphinx.ext.extlinks", "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. # Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"] templates_path = ["_templates"]