This repository was archived by the owner on Dec 22, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 1
1
import aiohttp
2
- import json
2
+ from . errors import InvalidEndpoint , InvalidToken , InvalidClientID
3
3
4
4
class Client :
5
5
def __init__ (self , token ):
6
6
self .auth = token
7
7
8
8
async def post (self , bot_id :str = None , guild_count :int = None ):
9
- async with aiohttp .ClientSession (headers = {'Authorization' : self . auth }) as s :
9
+ async with aiohttp .ClientSession (headers = {'Authorization' : 'e' }) as s :
10
10
async with s .post (f"https://discordbotindex.com/apiv1/bot/{ bot_id } " , data = {'server_count' : guild_count }) as r :
11
11
r = await r .json ()
12
- return r
12
+ if r == {"error" : "unauthorized" }:
13
+ raise InvalidToken ("You provided an invalid token." )
14
+ else :
15
+ return r
13
16
14
- #class Fetch:
15
17
async def fetch (bot_id , endpoint :str = None ):
16
18
async with aiohttp .ClientSession () as s :
17
19
async with s .get (f"https://discordbotindex.com/apiv1/bot/{ bot_id } " ) as r :
18
20
r = await r .json ()
19
- if endpoint is None :
20
- try :
21
- return r
22
- except :
23
- return "[dbipyt.0.1.2] Invalid client ID. Please provide a client ID with the bot_id argument."
21
+ if r == {"error" :"unknown_bot" }:
22
+ raise InvalidClientID (f"'{ bot_id } ' is not a valid ID. Please provide a correct client ID." )
23
+ elif r == {"error" :"param_must_be_int" }:
24
+ raise InvalidClientID ("Client IDs must be in int." )
25
+ elif endpoint is None :
26
+ return r
24
27
else :
25
28
try :
26
29
return r [endpoint ]
27
- except KeyError as e :
28
- return f"[dbipyt.0.1.2] Invalid endpoint: { e } "
30
+ except KeyError as error :
31
+ raise InvalidEndpoint ( error )
You can’t perform that action at this time.
0 commit comments