Skip to content

Commit

Permalink
feat: deprecated shard-related things
Browse files Browse the repository at this point in the history
  • Loading branch information
null8626 committed Feb 18, 2025
1 parent e13d619 commit 48e9c97
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion examples/hikari_example/callbacks/autopost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
7 changes: 1 addition & 6 deletions tests/test_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion topgg/autopost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions topgg/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion topgg/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_))

Expand Down
38 changes: 26 additions & 12 deletions topgg/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import dataclasses
import typing as t
import warnings
from datetime import datetime

KT = t.TypeVar("KT")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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

0 comments on commit 48e9c97

Please sign in to comment.