From 48e9c970d014e79f88afd69273c8e00df9e19e1d Mon Sep 17 00:00:00 2001 From: null8626 Date: Tue, 18 Feb 2025 13:20:16 +0700 Subject: [PATCH] feat: deprecated shard-related things --- examples/hikari_example/callbacks/autopost.py | 2 +- tests/test_type.py | 7 +--- topgg/autopost.py | 2 +- topgg/client.py | 14 +++---- topgg/data.py | 2 +- topgg/types.py | 38 +++++++++++++------ 6 files changed, 35 insertions(+), 30 deletions(-) diff --git a/examples/hikari_example/callbacks/autopost.py b/examples/hikari_example/callbacks/autopost.py index d50080e..e09a016 100644 --- a/examples/hikari_example/callbacks/autopost.py +++ b/examples/hikari_example/callbacks/autopost.py @@ -58,4 +58,4 @@ def on_autopost_error( def stats(app: hikari.GatewayBot = topgg.data(hikari.GatewayBot)): - return topgg.StatsWrapper(guild_count=len(app.cache.get_guilds_view()), shard_count=app.shard_count) + return topgg.StatsWrapper(guild_count=len(app.cache.get_guilds_view())) diff --git a/tests/test_type.py b/tests/test_type.py index 8cea66c..c66c81b 100644 --- a/tests/test_type.py +++ b/tests/test_type.py @@ -173,12 +173,7 @@ def test_server_vote_data_fields(server_vote_data: types.BotVoteData) -> None: def test_bot_stats_data_attrs(bot_stats_data: types.BotStatsData) -> None: - for count in ("server_count", "shard_count"): - assert isinstance(bot_stats_data[count], int) or bot_stats_data[count] is None - assert isinstance(bot_stats_data.shards, list) - if bot_stats_data.shards: - for shard in bot_stats_data.shards: - assert isinstance(shard, int) + assert isinstance(bot_stats_data["server_count"], int) or bot_stats_data["server_count"] is None def test_user_data_attrs(user_data: types.UserData) -> None: diff --git a/topgg/autopost.py b/topgg/autopost.py index 2df1d43..28a2abf 100644 --- a/topgg/autopost.py +++ b/topgg/autopost.py @@ -191,7 +191,7 @@ def stats(self, callback: t.Any = None) -> t.Any: @autopost.stats() def get_stats(client: Client = topgg.data(Client)): - return topgg.StatsWrapper(guild_count=len(client.guilds), shard_count=len(client.shards)) + return topgg.StatsWrapper(guild_count=len(client.guilds)) # somewhere after the event loop has started diff --git a/topgg/client.py b/topgg/client.py index 57ca47a..b3e5eb4 100644 --- a/topgg/client.py +++ b/topgg/client.py @@ -127,7 +127,7 @@ async def post_guild_count( shard_count: t.Any = None, shard_id: t.Any = None, ) -> None: - """Posts your bot's guild count and shards info to Top.gg. + """Posts your bot's guild count to Top.gg. .. _0 based indexing : https://en.wikipedia.org/wiki/Zero-based_numbering @@ -136,16 +136,12 @@ async def post_guild_count( Args: stats (:obj:`~.types.StatsWrapper`) - An instance of StatsWrapper containing guild_count, shard_count, and shard_id. + An instance of StatsWrapper containing guild_count. Keyword Arguments: guild_count (Optional[Union[:obj:`int`, List[:obj:`int`]]]) - Number of guilds the bot is in. Applies the number to a shard instead if shards are specified. + Number of guilds the bot is in. If not specified, length of provided client's property `.guilds` will be posted. - shard_count (Optional[:obj:`int`]) - The total number of shards. - shard_id (Optional[:obj:`int`]) - The index of the current shard. Top.gg uses `0 based indexing`_ for shards. Raises: TypeError @@ -172,11 +168,11 @@ async def post_guild_count( await self.http.post_guild_count(guild_count) async def get_guild_count(self) -> types.BotStatsData: - """Gets this bot's guild count and shard info from Top.gg. + """Gets this bot's guild count from Top.gg. Returns: :obj:`~.types.BotStatsData`: - The guild count and shards of a bot on Top.gg. + The guild count on Top.gg. Raises: :exc:`~.errors.ClientStateException` diff --git a/topgg/data.py b/topgg/data.py index 0d05668..b21d0a4 100644 --- a/topgg/data.py +++ b/topgg/data.py @@ -60,7 +60,7 @@ def data(type_: t.Type[T]) -> T: @autopost.stats() def get_stats(client: Client = topgg.data(Client)): - return topgg.StatsWrapper(guild_count=len(client.guilds), shard_count=len(client.shards)) + return topgg.StatsWrapper(guild_count=len(client.guilds)) """ return t.cast(T, Data(type_)) diff --git a/topgg/types.py b/topgg/types.py index 46721f8..670b937 100644 --- a/topgg/types.py +++ b/topgg/types.py @@ -26,6 +26,7 @@ import dataclasses import typing as t +import warnings from datetime import datetime KT = t.TypeVar("KT") @@ -115,10 +116,6 @@ def parse_bot_stats_dict(d: dict) -> dict: if "server_count" not in data: data["server_count"] = None - if "shards" not in data: - data["shards"] = [] - if "shard_count" not in data: - data["shard_count"] = None return data @@ -270,20 +267,34 @@ def __init__(self, **kwargs: t.Any): class BotStatsData(DataDict[str, t.Any]): - """Model that contains information about a listed bot's guild and shard count.""" + """Model that contains information about a listed bot's guild count.""" __slots__: t.Tuple[str, ...] = () server_count: t.Optional[int] """The amount of servers the bot is in.""" - shards: t.List[int] - """The amount of servers the bot is in per shard.""" - shard_count: t.Optional[int] - """The amount of shards a bot has.""" def __init__(self, **kwargs: t.Any): super().__init__(**parse_bot_stats_dict(kwargs)) + @property + def shards(self) -> t.List[int]: + """DEPRECATED: No longer supported by Top.gg API v0. At the moment, this will always return an empty array.""" + + warnings.warn( + "No longer supported by Top.gg API v0. At the moment, this will always return an empty array.", + DeprecationWarning, + ) + return [] + + @property + def shard_count(self) -> t.Optional[int]: + """DEPRECATED: No longer supported by Top.gg API v0. At the moment, this will always return None.""" + + warnings.warn( + "No longer supported by Top.gg API v0. At the moment, this will always return None.", DeprecationWarning + ) + class BriefUserData(DataDict[str, t.Any]): """Model that contains brief information about a Top.gg user.""" @@ -405,7 +416,10 @@ class StatsWrapper: """The guild count.""" shard_count: t.Optional[int] = None - """The shard count.""" - shard_id: t.Optional[int] = None - """The shard ID the guild count belongs to.""" + + def __init__(self, guild_count: int, **kwargs): + if kwargs.get("shard_count") or kwargs.get("shard_id"): + warnings.warn("Posting shard-related data no longer has a use by Top.gg API v0.", DeprecationWarning) + + self.guild_count = guild_count