slay.py

 1import json, requests
 2
 3from typing import TypedDict
 4from urllib3.exceptions import InsecureRequestWarning
 5
 6requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
 7
 8from slay.utils import export
 9
10__all__ = ["connection", "connections", "socket"]
11
12@export
13class PlayerProfile(TypedDict):
14    """ Type of player profile. """
15
16    id: int
17    name: str
18    xp: int
19    elo: int | float
20    clan_tag: str
21    kills: int
22    deaths: int
23    timeOfCreation: int
24    timeOfLastLogin: int
25    personal_text: str
26    ts_nick: int
27    name_color_select: int
28    isLegacy: int
29    hat: int
30    killedWithGunCounter: list[int]
31    elo2: int | float
32    elo3: int | float
33    online: bool
34
35@export
36def get_player_profile(id: int, timeout: int = 10) -> PlayerProfile:
37    response = requests.get(
38        f"https://54.37.204.175:3000/user/{id}", verify=False, timeout=timeout
39    )
40
41    if not response.ok:
42        return None
43    
44    playerInfo = json.loads(response.text)
45    playerInfo["killedWithGunCounter"] = json.loads(
46        playerInfo["killedWithGunCounter"]
47    )
48
49    return playerInfo
@export
class PlayerProfile(typing.TypedDict):
13@export
14class PlayerProfile(TypedDict):
15    """ Type of player profile. """
16
17    id: int
18    name: str
19    xp: int
20    elo: int | float
21    clan_tag: str
22    kills: int
23    deaths: int
24    timeOfCreation: int
25    timeOfLastLogin: int
26    personal_text: str
27    ts_nick: int
28    name_color_select: int
29    isLegacy: int
30    hat: int
31    killedWithGunCounter: list[int]
32    elo2: int | float
33    elo3: int | float
34    online: bool

Type of player profile.

id: int
name: str
xp: int
elo: int | float
clan_tag: str
kills: int
deaths: int
timeOfCreation: int
timeOfLastLogin: int
personal_text: str
ts_nick: int
name_color_select: int
isLegacy: int
hat: int
killedWithGunCounter: list[int]
elo2: int | float
elo3: int | float
online: bool
@export
def get_player_profile(id: int, timeout: int = 10) -> PlayerProfile:
36@export
37def get_player_profile(id: int, timeout: int = 10) -> PlayerProfile:
38    response = requests.get(
39        f"https://54.37.204.175:3000/user/{id}", verify=False, timeout=timeout
40    )
41
42    if not response.ok:
43        return None
44    
45    playerInfo = json.loads(response.text)
46    playerInfo["killedWithGunCounter"] = json.loads(
47        playerInfo["killedWithGunCounter"]
48    )
49
50    return playerInfo