From ba766161dccb8393427ba549d2091c0f77d5d200 Mon Sep 17 00:00:00 2001 From: MadCat9958 Date: Sat, 3 Jun 2023 23:12:20 +0300 Subject: [PATCH 1/6] base --- boticordpy/http.py | 46 +++------------- boticordpy/types.py | 119 ++++++++++++++++-------------------------- boticordpy/webhook.py | 2 + 3 files changed, 54 insertions(+), 113 deletions(-) diff --git a/boticordpy/http.py b/boticordpy/http.py index c8ca187..93b055e 100644 --- a/boticordpy/http.py +++ b/boticordpy/http.py @@ -20,7 +20,7 @@ class HttpClient: loop: `asyncio loop` """ - def __init__(self, auth_token: str, version: int = 1, **kwargs): + def __init__(self, auth_token: str, version: int = 3, **kwargs): self.token = auth_token self.API_URL = f"https://api.boticord.top/v{version}/" @@ -60,56 +60,26 @@ class HttpClient: def get_bot_info(self, bot_id: int): """Get information about the specified bot""" - return self.make_request("GET", f"bot/{bot_id}") + return self.make_request("GET", f"bots/{bot_id}") + # TODO def get_bot_comments(self, bot_id: int): """Get list of specified bot comments""" return self.make_request("GET", f"bot/{bot_id}/comments") - def post_bot_stats(self, stats: dict): + def post_bot_stats(self, bot_id: int, stats: dict): """Post bot's stats""" - return self.make_request("POST", "stats", json=stats) + return self.make_request("POST", f"bots/{bot_id}", json=stats) 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}") diff --git a/boticordpy/types.py b/boticordpy/types.py index 8998a36..9f44e7a 100644 --- a/boticordpy/types.py +++ b/boticordpy/types.py @@ -98,105 +98,74 @@ class Bot(ApiData): id: str """Bot's Id""" - short_code: typing.Optional[str] - """Bot's page short code""" + name: str + """Bot's name""" - page_links: list - """List of bot's page urls""" - - server: dict - """Bot's support server""" - - bumps: int - """Bumps count""" - - added: str - """How many times users have added the bot?""" - - prefix: str - """Bot's commands prefix""" - - permissions: int - """Bot's permissions""" - - tags: list - """Bot's search-tags""" - - developers: list - """List of bot's developers Ids""" - - links: typing.Optional[dict] - """Bot's social medias""" - - library: typing.Optional[str] - """Bot's library""" - - short_description: typing.Optional[str] + shortDescription: str """Bot's short description""" - long_description: typing.Optional[str] + description: str """Bot's long description""" - badge: typing.Optional[str] - """Bot's badge""" + avatar: typing.Optional[str] + """Bot's avatar""" - stats: dict - """Bot's stats""" + shortLink: typing.Optional[str] + """Bot's page short code""" - status: str - """Bot's approval status""" + inviteLink: str + """Bot's invite link""" - def __init__(self, **kwargs): - super().__init__(**parse_with_information_dict(kwargs)) + premiumActive: bool + """Bot's premium status""" + premiumSplashURL: typing.Optional[str] + """Bot's splash URL""" -class Server(ApiData): - """This model represents a server, returned from the Boticord API""" + premiumAutoFetch: typing.Optional[bool] + """Bot's auto fetch status""" - id: str - """Server's Id""" + standardBannerID: int + """Bot's standart banner ID""" - short_code: typing.Optional[str] - """Server's page short code""" + premiumBannerURL: typing.Optional[str] + """Bot's premium banner URL""" - status: str - """Server's approval status""" + owner: str + """Bot's owner""" - page_links: list - """List of server's page urls""" + status: int + """Bot's status""" - bot: dict - """Bot where this server is used for support users""" + prefix: str + """Bot's prefix""" - name: str - """Name of the server""" + discriminator: str + """Bot's discriminator (soon deprecated)""" - avatar: str - """Server's avatar""" + createdDate: str + """Bot's creation date""" - members: list - """Members counts - `[all, online]`""" + supportServerInviteLink: typing.Optional[str] + """Bot's support server""" - owner: typing.Optional[str] - """Server's owner Id""" + library: typing.Optional[int] + """Bot's library""" - bumps: int - """Bumps count""" + guilds: typing.Optional[int] + """Bot's guilds count""" - tags: list - """Server's search-tags""" + shards: typing.Optional[int] + """Bot's shards count""" - links: dict - """Server's social medias""" + members: typing.Optional[int] + """Bot's members count""" - short_description: typing.Optional[str] - """Server's short description""" + website: typing.Optional[str] + """Bot's website""" - long_description: typing.Optional[str] - """Server's long description""" - - badge: typing.Optional[str] - """Server's badge""" + upCount: int + """Bot's up count""" def __init__(self, **kwargs): super().__init__(**parse_with_information_dict(kwargs)) diff --git a/boticordpy/webhook.py b/boticordpy/webhook.py index 49aa084..2535f9d 100644 --- a/boticordpy/webhook.py +++ b/boticordpy/webhook.py @@ -11,6 +11,8 @@ class Webhook: """Represents a client that can be used to work with BotiCord Webhooks. IP of the server - your machine IP. (`0.0.0.0`) + Note: you need to have IPV6 support to use this + Args: x_hook_key (:obj:`str`) X-hook-key to check the auth of incoming request. From 1aac25cb63c465ab8de512e36836b74e0c2555df Mon Sep 17 00:00:00 2001 From: MadCat9958 Date: Sun, 4 Jun 2023 11:37:43 +0300 Subject: [PATCH 2/6] vs code users moment --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3280530..bdf246b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ boticordpy.egg-info _testing.py /.pytest_cache /docs/build/ +.vscode \ No newline at end of file From ffdd54439be212633a1520c5a79b5cfcf971735d Mon Sep 17 00:00:00 2001 From: MadCat9958 Date: Sun, 4 Jun 2023 12:27:17 +0300 Subject: [PATCH 3/6] UserProfile + ResourceServer --- boticordpy/types.py | 256 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 249 insertions(+), 7 deletions(-) diff --git a/boticordpy/types.py b/boticordpy/types.py index 7bd826a..c72bf0f 100644 --- a/boticordpy/types.py +++ b/boticordpy/types.py @@ -226,19 +226,80 @@ class BotLibrary(IntEnum): class ResourceStatus(IntEnum): - """Bot status on monitoring""" + """Bot/server status on monitoring""" HIDDEN = 0 - """Bot is hidden""" + """Bot/server is hidden""" PUBLIC = 1 - """Bot is public""" + """Bot/server is public""" BANNED = 2 - """Bot is banned""" + """Bot/server is banned""" PENDING = 3 - """Bor is pending""" + """Bot/server 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): @@ -316,7 +377,7 @@ class UserLinks(APIObjectBase): The dictionary to convert into a UserLinks. """ - self: ResourceUp = super().__new__(cls) + self: UserLinks = super().__new__(cls) self.vk = data.get("vk") self.telegram = data.get("telegram") @@ -325,6 +386,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) @@ -426,7 +518,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"] @@ -439,6 +531,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) From b99954a59777dd806ab88cb09e5cd97dbd658caf Mon Sep 17 00:00:00 2001 From: MadCat9958 Date: Sun, 4 Jun 2023 12:33:54 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- boticordpy/types.py | 71 ++++----------------------------------------- 1 file changed, 5 insertions(+), 66 deletions(-) diff --git a/boticordpy/types.py b/boticordpy/types.py index bcbdc5d..57d286d 100644 --- a/boticordpy/types.py +++ b/boticordpy/types.py @@ -249,80 +249,19 @@ class BotLibrary(IntEnum): class ResourceStatus(IntEnum): - """Status of the project on monitoring""" + """Bot status on monitoring""" HIDDEN = 0 - """is hidden""" + """Bot is hidden""" PUBLIC = 1 - """is public""" + """Bot is public""" BANNED = 2 - """is banned""" + """Bot is banned""" PENDING = 3 - """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""" + """Bor is pending""" class ServerTag(IntEnum): From ea4f7e33e8c5c23fd59ce488978e3b43dc502c1e Mon Sep 17 00:00:00 2001 From: MadCat9958 Date: Sun, 4 Jun 2023 12:41:25 +0300 Subject: [PATCH 5/6] fix --- boticordpy/http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boticordpy/http.py b/boticordpy/http.py index bac1f75..a0f2776 100644 --- a/boticordpy/http.py +++ b/boticordpy/http.py @@ -55,7 +55,7 @@ class HttpClient: def post_bot_stats(self, bot_id: typing.Union[str, int], stats: dict): """Post bot's stats""" - return self.make_request("POST", f"bots/{bot_id}", json=stats) + return self.make_request("POST", f"bots/{bot_id}/stats", json=stats) def get_server_info(self, server_id: int): """Get information about specified server""" From cf69cc2cfc8608135b01628b1a35c157efda3537 Mon Sep 17 00:00:00 2001 From: MadCat9958 Date: Sun, 4 Jun 2023 12:42:50 +0300 Subject: [PATCH 6/6] ono sluchaino --- boticordpy/types.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/boticordpy/types.py b/boticordpy/types.py index 57d286d..48bf1b9 100644 --- a/boticordpy/types.py +++ b/boticordpy/types.py @@ -249,19 +249,19 @@ class BotLibrary(IntEnum): class ResourceStatus(IntEnum): - """Bot status on monitoring""" + """Status of the project on monitoring""" HIDDEN = 0 - """Bot is hidden""" + """is hidden""" PUBLIC = 1 - """Bot is public""" + """is public""" BANNED = 2 - """Bot is banned""" + """is banned""" PENDING = 3 - """Bor is pending""" + """is pending""" class ServerTag(IntEnum):