Skip to content

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.

close abstractmethod async #

close()

Close the counter.

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:

open abstractmethod async #

open()

Open the counter.

AbstractManager #

Bases: Protocol

Abstract class used for managing services.

cache abstractmethod property #

cache

The cache service this manager is bound to.

counter abstractmethod property #

counter

The country strategy this manager was initialised with.

event_manager abstractmethod property #

event_manager

The event manager this manager is bound to.

rest abstractmethod property #

rest

The REST client this manager is bound to.

shards abstractmethod property #

shards

The shard aware client this manager is bound to.

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.

__init__ #

__init__(token)

Initialise a bots.gg service.

Parameters:

  • token (str) –

    Authorization token used to update the bot's status.

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.

__init__ #

__init__(token)

Initialise a discordbotlist.com service.

Parameters:

  • token (str) –

    Authorization token used to update the bot's status.

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.

is_alive property #

is_alive

Wwhether this manager is active.

__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_manager is 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:

  • ValueError

    If the manager failed to find a suitable standard strategy to use when strategy was left as None.

    If event_managed is passed as True when event_manager is None.

add_service #

add_service(service, /, *, repeat=datetime.timedelta(hours=1))

Add a service to this manager.

Parameters:

Returns:

  • Self

    Object of this service manager.

Raises:

close async #

close()

Close this manager.

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:

Raises:

  • ValueError

    If the manager failed to find a suitable standard strategy to use when strategy was 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:

Raises:

  • ValueError

    If the manager failed to find a suitable standard strategy to use when strategy was left as None.

open async #

open()

Start this manager.

Raises:

remove_service #

remove_service(service)

Remove the first found entry of the registered service.

Parameters:

  • service (ServiceSig) –

    Service callback to unregister.

Raises:

with_service #

with_service(*, repeat=datetime.timedelta(hours=1))

Add a service to this manager by decorating a function.

Parameters:

Returns:

Raises:

TopGGService #

https://top.gg status update service.

__init__ #

__init__(token)

Initialise a top.gg service.

Parameters:

  • token (str) –

    Authorization token used to update the bot's status.