yuyo.list_status#
Utility classes for updating a bot's guild count on several bot list services.
ServiceSig module-attribute #
ServiceSig = Callable[['AbstractManager'], Coroutine[Any, Any, None]]
Signature of a callback used to update a service.
AbstractCountStrategy #
Bases: ABC
Protocol of a class used for calculating the bot's guild count.
is_shard_bound abstractmethod property #
is_shard_bound
Whether this count is just for the current shards.
count abstractmethod async #
count()
Get a possibly cached guild count from this counter.
Returns:
-
int–The current guild count(s).
If this is an int then this is a global count. If this is a mapping then this is shard-specific counts.
Raises:
-
CountUnknownError–If the count is currently unknown.
AbstractManager #
Bases: Protocol
Abstract class used for managing services.
user_agent abstractmethod property #
user_agent
User agent services within this manager should use for requests.
get_me abstractmethod async #
get_me()
Get user object of the bot this manager is bound to.
Returns:
-
User–User object of the bot this manager is bound to.
get_session abstractmethod #
get_session()
Get an aiohttp session to use to make requests within the services.
Returns:
-
ClientSession–an aiohttp session to use to make requests within the services.
Raises:
-
RuntimeError–- If this is called in an environment with no running event loop.
- If the client isn't running.
BotsGGService #
https://discord.bots.gg status update service.
CacheStrategy #
Bases: _LoadableStrategy
Cache based implementation of AbstractCountStrategy.
This tracks per-shard guild counts.
Warning
This will only function properly if GUILD intents are declared and the guild cache resource is enabled.
__init__ #
__init__(cache, shards)
Initialise a cache strategy.
Parameters:
-
cache(Cache) –The cache object this should use for getting the guild count.
-
shards(ShardAware) –The shard aware client this should use for grouping counts per-shard.
CountUnknownError #
Bases: RuntimeError
Error raised when the count is currently unknown.
DiscordBotListService #
https://discordbotlist.com status update service.
EventStrategy #
Bases: _LoadableStrategy
Cache based implementation of AbstractCountStrategy.
This tracks per-guild counts.
Warning
This will only function properly if GUILD intents are declared.
__init__ #
__init__(event_manager, shards)
Initialise an event etrategy.
Note
You usually won't need to initialise this yourself as ServiceManager will automatically pick this strategy if the bot config matches it.
Parameters:
-
event_manager(EventManager) –The event manager this should use to track shard guild counts.
-
shards(ShardAware) –The shard manager this should use to track shard guild counts.
SakeStrategy #
Bases: AbstractCountStrategy
Async cache based implementation of AbstractCountStrategy.
This relies on Sake and tracks the global guild count.
__init__ #
__init__(cache)
Initialise a Sake strategy.
Unlike CacheStrategy and EventStrategy this strategy must be directly initialised and passed to ServiceManager.__init__ as strategy=.
Parameters:
-
cache(GuildCache) –The Sake guild cache to use to get the guild count.
ServiceManager #
Bases: AbstractManager
Standard service manager.
__init__ #
__init__(rest, /, *, cache=None, event_manager=None, shards=None, event_managed=None, strategy=None, user_agent=None)
Initialise a service manager.
Note
For an easier way to initialise the manager from a bot see ServiceManager.from_gateway_bot, and ServiceManager.from_tanjun.
Parameters:
-
rest(RESTClient) –The RESTAware Hikari client to bind this manager to.
-
cache(Optional[Cache], default:None) –The cache aware Hikari client this manager should use.
-
event_manager(Optional[EventManager], default:None) –The event manager aware Hikari client this manager should use.
-
shards(Optional[ShardAware], default:None) –The shard aware Hikari client this manager should use.
-
event_managed(Optional[bool], default:None) –Whether this client should be automatically opened and closed based on
event_manager's lifetime events.Defaults to True when
event_manageris passed. -
strategy(Optional[AbstractCountStrategy], default:None) –The counter strategy this manager should expose to services.
If this is left as None then the manager will try to pick a suitable standard strategy based on the provided Hikari clients.
-
user_agent(Optional[str], default:None) –Override the standard user agent used during requests to bot list services.
Raises:
add_service #
add_service(service, /, *, repeat=datetime.timedelta(hours=1))
Add a service to this manager.
Parameters:
-
service(ServiceSig) –Asynchronous callback used to update this service.
-
repeat(Union[timedelta, int, float], default:timedelta(hours=1)) –How often this service should be updated in seconds.
Returns:
-
Self–Object of this service manager.
Raises:
-
ValueError–If repeat is less than 1 second.
-
RuntimeError–If the client is already running.
from_gateway_bot classmethod #
from_gateway_bot(bot, /, *, event_managed=True, strategy=None, user_agent=None)
Build a service manager from a gateway bot.
Parameters:
-
bot(ShardAware & RESTAware & EventManagerAware) –The gateway bot to build a service manager from.
-
event_managed(bool, default:True) –Whether this client should be automatically opened and closed based on
bot's lifetime events. -
strategy(Optional[AbstractCountStrategy], default:None) –The counter strategy this manager should expose to services.
If this is left as None then the manager will try to pick a suitable standard strategy based on the provided Hikari clients.
-
user_agent(Optional[str], default:None) –Override the standard user agent used during requests to bot list services.
Returns:
-
ServiceManager–The build service manager.
Raises:
-
ValueError–If the manager failed to find a suitable standard strategy to use when
strategywas left as None.
from_tanjun classmethod #
from_tanjun(tanjun_client, /, *, tanjun_managed=True, strategy=None, user_agent=None)
Build a service manager from a Tanjun client.
This will use the Tanjun client's alluka client and registers ServiceManager and AbstractManager as type dependencies on Tanjun.
Parameters:
-
tanjun_client(Client) –The Tanjun client to build a service manager from.
-
tanjun_managed(bool, default:True) –Whether this client should be automatically opened and closed based on the Tanjun client's lifetime client callback.
-
strategy(Optional[AbstractCountStrategy], default:None) –The counter strategy this manager should expose to services.
If this is left as None then the manager will try to pick a suitable standard strategy based on the provided Hikari clients.
-
user_agent(Optional[str], default:None) –Override the standard user agent used during requests to bot list services.
Returns:
-
ServiceManager–The build service manager.
Raises:
-
ValueError–If the manager failed to find a suitable standard strategy to use when
strategywas left as None.
remove_service #
remove_service(service)
Remove the first found entry of the registered service.
Parameters:
-
service(ServiceSig) –Service callback to unregister.
Raises:
-
RuntimeError–If called while the manager is active.
-
ValueError–If the service callback isn't found.
with_service #
with_service(*, repeat=datetime.timedelta(hours=1))
Add a service to this manager by decorating a function.
Parameters:
-
repeat(Union[timedelta, int, float], default:timedelta(hours=1)) –How often this service should be updated in seconds.
Returns:
-
Callable[[ServiceSig], ServiceSig]–Decorator callback used to add a service.
Raises:
-
ValueError–If repeat is less than 1 second.
-
RuntimeError–If the client is already running.
TopGGService #
https://top.gg status update service.