add support for BotiCord API v2

This commit is contained in:
grey-cat-1908 2022-06-08 19:05:06 +03:00
parent 9db08f978a
commit 45b04409d4
3 changed files with 12 additions and 5 deletions

View file

@ -10,7 +10,7 @@ __title__ = "boticordpy"
__author__ = "Marakarka"
__license__ = "MIT"
__copyright__ = "Copyright 2022 Marakarka"
__version__ = "2.2.0"
__version__ = "2.2.1"
from .client import BoticordClient
from .webhook import Webhook

View file

@ -8,22 +8,29 @@ from .autopost import AutoPost
class BoticordClient:
"""Represents a client that can be used to interact with the BotiCord API.
.. warning::
In BotiCord API v2 there are some changes with token.
[Read more here](https://docs.boticord.top/topics/v1vsv2/)
Note:
Remember that every http method can return http exception.
Args:
token (:obj:`str`)
Your bot's Boticord API Token.
version (:obj:`int`)
BotiCord API version
"""
__slots__ = ("http", "_autopost", "_token")
http: HttpClient
def __init__(self, token=None):
def __init__(self, token: str = None, version: int = 1):
self._token = token
self._autopost: typing.Optional[AutoPost] = None
self.http = HttpClient(token)
self.http = HttpClient(token, version)
async def get_bot_info(self, bot_id: int) -> boticord_types.Bot:
"""Gets information about specified bot.

View file

@ -20,9 +20,9 @@ class HttpClient:
loop: `asyncio loop`
"""
def __init__(self, auth_token, **kwargs):
def __init__(self, auth_token: str, version: int = 1, **kwargs):
self.token = auth_token
self.API_URL = "https://api.boticord.top/v1/"
self.API_URL = f"https://api.boticord.top/v{version}/"
loop = kwargs.get("loop") or asyncio.get_event_loop()