Merge pull request #10 from MadCat9958/v3

UserProfile & ResourceServer
This commit is contained in:
Виктор 2023-06-04 12:46:02 +03:00 committed by GitHub
commit 6d69556d93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 247 additions and 35 deletions

1
.gitignore vendored
View file

@ -10,3 +10,4 @@ boticordpy.egg-info
_testing.py
/.pytest_cache
/docs/build/
.vscode

View file

@ -59,44 +59,13 @@ class HttpClient:
def get_server_info(self, server_id: int):
"""Get information about specified server"""
return self.make_request("GET", f"server/{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 post_server_stats(self, payload: dict):
"""Post server's stats"""
return self.make_request("POST", "server", json=payload)
def get_user_info(self, user_id: int):
"""Get information about the user"""
return self.make_request("GET", f"profile/{user_id}")
def get_user_comments(self, user_id: int):
"""Get specified user's comments"""
return self.make_request("GET", f"user/{user_id}/comments")
def get_user_bots(self, user_id: int):
"""Get bots of specified user"""
return self.make_request("GET", f"bots/{user_id}")
def get_my_shorted_links(self, code: str = None):
"""Get shorted links of an authorized user"""
body = {"code": code} if code is not None else {}
return self.make_request("POST", "links/get", json=body)
def create_shorted_link(self, code: str, link: str, *, domain: LinkDomain = 1):
"""Create new shorted link"""
return self.make_request(
"POST",
"links/create",
json={"code": code, "link": link, "domain": int(domain)},
)
def delete_shorted_link(self, code: str, domain: LinkDomain = 1):
"""Delete shorted link"""
return self.make_request(
"POST", "links/delete", json={"code": code, "domain": int(domain)}
)
return self.make_request("GET", f"users/{user_id}")

View file

@ -264,6 +264,67 @@ class ResourceStatus(IntEnum):
"""is pending"""
class ServerTag(IntEnum):
"""Tags of the server"""
SPEAKING = 130
"""Speaking"""
FUN = 131
"""Fun"""
GAMES = 132
"""Games"""
CINEMA = 133
"""Cinema"""
ANIME = 134
"""Anime"""
ART = 135
"""Art"""
CODING = 136
"""Coding"""
MUSIC = 137
"""Music"""
ADULT = 138
"""18+"""
ROLEPLAY = 139
"""Role-Play"""
HUMOUR = 140
"""Humour"""
GENSHIN = 160
"""Genshin"""
MINECRAFT = 161
"""Minecraft"""
GTA = 162
"""GTA"""
CS = 163
"""CS"""
DOTA = 164
"""Dota"""
AMONG_US = 165
"""Among Us"""
FORTNITE = 166
"""Fortnite"""
BRAWL_STARS = 167
"""Brawl Stars"""
class BotTag(IntEnum):
"""Tags of the bot"""
@ -348,6 +409,37 @@ class UserLinks(APIObjectBase):
self.custon = data.get("custom")
return self
@dataclass(repr=False)
class UserBadge(APIObjectBase):
"""Information about user's profile badge"""
id: int
"""Badge's ID"""
name: str
"""Badge's name"""
asset_url: str
"""Badge's icon URL"""
@classmethod
def from_dict(cls, data: dict):
"""Generate a UserBadge from the given data.
Parameters
----------
data: :class:`dict`
The dictionary to convert into a UserBadge.
"""
self: UserBadge = super().__new__(cls)
self.id = data['id']
self.name = data['name']
self.asset_url = data['assetURL']
return self
@dataclass(repr=False)
@ -449,7 +541,7 @@ class PartialUser(APIObjectBase):
The dictionary to convert into a PartialUser.
"""
self: PartialUser = super().__new__(cls)
self: cls = super().__new__(cls)
self.username = data["username"]
self.discriminator = data["discriminator"]
@ -462,6 +554,156 @@ class PartialUser(APIObjectBase):
self.short_domain = data.get("shortDomain")
return self
@dataclass(repr=False)
class ResourceBot(APIObjectBase):
"""Tak nado"""
@dataclass(repr=False)
class ResourceServer(APIObjectBase):
"""Information about server from BotiCord."""
id: str
"""Server's ID"""
name: str
"""Server's name"""
short_description: str
"""Server's short description"""
description: str
"""Server's description"""
avatar: Optional[str]
"""Server's avatar"""
short_link: Optional[str]
"""Server's short link"""
invite_link: str
"""Server's invite link"""
premium_active: bool
"""Server's premium state"""
premium_auto_fetch: Optional[bool]
"""Server's premium auto fetch state"""
premium_banner_url: Optional[str]
"""Server's premium banner URL"""
premium_splash_url: Optional[str]
"""Server's premium splash URL"""
standart_banner_id: int
"""Server's standart banner ID"""
owner: str
"""Server's owner ID"""
status: ResourceStatus
"""Server's status"""
ratings: List[ResourceRating]
"""Server's ratings"""
created_date: datetime
"""Server's creation time"""
members: Optional[int]
"""Server's members count"""
website: Optional[str]
"""Server's website"""
tags: List[ServerTag]
"""Server's tags"""
moderators: List[PartialUser]
"""Server's moderators"""
up_count: int
"""Server's up count"""
ups: Optional[ResourceUp]
"""Server's ups"""
@classmethod
def from_dict(cls, data: dict):
"""Generate a ResourceServer from the given data.
Parameters
----------
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.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.status = ResourceStatus(data.get("status"))
self.ratings = [
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"
)
self.tags = [ServerTag(tag) for tag in data.get("tags", [])]
self.ups = [ResourceUp.from_dict(up) for up in data.get("ups", [])]
self.moderators = [
PartialUser.from_dict(mod) for mod in data.get("moderators", [])
]
self.members = data.get("memberCount")
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"""
@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)