From eaad5d928c254438f70f1ac7634a418d4a686fad Mon Sep 17 00:00:00 2001 From: ChrisLovering Date: Thu, 10 Nov 2022 21:42:51 +0000 Subject: Deploying to docs from @ python-discord/bot-core@a6760a64bcec5ba77709492ba33b6bfba1f58e84 🚀 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v9.0.0/output/pydis_core.async_stats.html | 473 +++++++++++++++ v9.0.0/output/pydis_core.exts.html | 415 +++++++++++++ v9.0.0/output/pydis_core.html | 738 +++++++++++++++++++++++ v9.0.0/output/pydis_core.site_api.html | 621 +++++++++++++++++++ v9.0.0/output/pydis_core.utils.caching.html | 487 +++++++++++++++ v9.0.0/output/pydis_core.utils.channel.html | 483 +++++++++++++++ v9.0.0/output/pydis_core.utils.commands.html | 456 ++++++++++++++ v9.0.0/output/pydis_core.utils.cooldown.html | 506 ++++++++++++++++ v9.0.0/output/pydis_core.utils.function.html | 497 +++++++++++++++ v9.0.0/output/pydis_core.utils.html | 561 +++++++++++++++++ v9.0.0/output/pydis_core.utils.interactions.html | 525 ++++++++++++++++ v9.0.0/output/pydis_core.utils.logging.html | 484 +++++++++++++++ v9.0.0/output/pydis_core.utils.members.html | 469 ++++++++++++++ v9.0.0/output/pydis_core.utils.regex.html | 466 ++++++++++++++ v9.0.0/output/pydis_core.utils.scheduling.html | 599 ++++++++++++++++++ 15 files changed, 7780 insertions(+) create mode 100644 v9.0.0/output/pydis_core.async_stats.html create mode 100644 v9.0.0/output/pydis_core.exts.html create mode 100644 v9.0.0/output/pydis_core.html create mode 100644 v9.0.0/output/pydis_core.site_api.html create mode 100644 v9.0.0/output/pydis_core.utils.caching.html create mode 100644 v9.0.0/output/pydis_core.utils.channel.html create mode 100644 v9.0.0/output/pydis_core.utils.commands.html create mode 100644 v9.0.0/output/pydis_core.utils.cooldown.html create mode 100644 v9.0.0/output/pydis_core.utils.function.html create mode 100644 v9.0.0/output/pydis_core.utils.html create mode 100644 v9.0.0/output/pydis_core.utils.interactions.html create mode 100644 v9.0.0/output/pydis_core.utils.logging.html create mode 100644 v9.0.0/output/pydis_core.utils.members.html create mode 100644 v9.0.0/output/pydis_core.utils.regex.html create mode 100644 v9.0.0/output/pydis_core.utils.scheduling.html (limited to 'v9.0.0/output') diff --git a/v9.0.0/output/pydis_core.async_stats.html b/v9.0.0/output/pydis_core.async_stats.html new file mode 100644 index 00000000..cd5e3f98 --- /dev/null +++ b/v9.0.0/output/pydis_core.async_stats.html @@ -0,0 +1,473 @@ + + + + + + + + + async_stats - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

async_stats#

+

An async transport method for statsd communication.

+
+
+class AsyncStatsClient(loop, host='localhost', port=8125, prefix=None)[source]#
+

Bases: StatsClientBase

+

An async implementation of statsd.client.base.StatsClientBase that supports async stat communication.

+
+
+__init__(loop, host='localhost', port=8125, prefix=None)[source]#
+

Create a new AsyncStatsClient.

+
+
Parameters:
+
+
+
+
+ +
+
+async create_socket()[source]#
+

Use asyncio.loop.create_datagram_endpoint from the loop given on init to create a socket.

+
+
Return type:
+

None

+
+
+
+ +
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.exts.html b/v9.0.0/output/pydis_core.exts.html new file mode 100644 index 00000000..7f219ccf --- /dev/null +++ b/v9.0.0/output/pydis_core.exts.html @@ -0,0 +1,415 @@ + + + + + + + + + Pydis_Core Exts - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

Pydis_Core Exts#

+

Reusable Discord cogs.

+
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.html b/v9.0.0/output/pydis_core.html new file mode 100644 index 00000000..2e7f123f --- /dev/null +++ b/v9.0.0/output/pydis_core.html @@ -0,0 +1,738 @@ + + + + + + + + + Pydis_Core - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

Pydis_Core#

+

Useful utilities and tools for Discord bot development.

+
+
+class BotBase(*args, guild_id, allowed_roles, http_session, redis_session=None, api_client=None, statsd_url=None, **kwargs)[source]#
+

Bases: Bot

+

A sub-class that implements many common features that Python Discord bots use.

+
+
+__init__(*args, guild_id, allowed_roles, http_session, redis_session=None, api_client=None, statsd_url=None, **kwargs)[source]#
+

Initialise the base bot instance.

+
+
Parameters:
+
+
+
+
+ +
+
+async add_cog(cog)[source]#
+

Add the given cog to the bot and log the operation.

+
+
Return type:
+

None

+
+
+
+ +
+
+add_command(command)[source]#
+

Add command as normal and then add its root aliases to the bot.

+
+
Return type:
+

None

+
+
+
+ +
+
+clear()[source]#
+

Not implemented! Re-instantiate the bot instead of attempting to re-use a closed one.

+
+
Return type:
+

None

+
+
+
+ +
+
+async close()[source]#
+

Close the Discord connection, and the aiohttp session, connector, statsd client, and resolver.

+
+
Return type:
+

None

+
+
+
+ +
+
+async load_extensions(module)[source]#
+

Load all the extensions within the given module and save them to self.all_extensions.

+

This should be ran in a task on the event loop to avoid deadlocks caused by wait_for calls.

+
+
Return type:
+

None

+
+
+
+ +
+
+async log_to_dev_log(message)[source]#
+

Log the given message to #dev-log.

+
+
Return type:
+

None

+
+
+
+ +
+
+async on_guild_available(guild)[source]#
+

Set the internal guild available event when self.guild_id becomes available.

+

If the cache appears to still be empty (no members, no channels, or no roles), the event +will not be set and guild_available_but_cache_empty event will be emitted.

+
+
Return type:
+

None

+
+
+
+ +
+
+async on_guild_unavailable(guild)[source]#
+

Clear the internal guild available event when self.guild_id becomes unavailable.

+
+
Return type:
+

None

+
+
+
+ +
+
+async ping_services()[source]#
+

Ping all required services on setup to ensure they are up before starting.

+
+
Return type:
+

None

+
+
+
+ +
+
+remove_command(name)[source]#
+

Remove a command/alias as normal and then remove its root aliases from the bot.

+

Individual root aliases cannot be removed by this function. +To remove them, either remove the entire command or manually edit bot.all_commands.

+
+
Return type:
+

Optional[Command]

+
+
+
+ +
+
+async setup_hook()[source]#
+

An async init to startup generic services.

+

Connects to statsd, and calls +AsyncStatsClient.create_socket +and ping_services().

+
+
Return type:
+

None

+
+
+
+ +
+
+async wait_until_guild_available()[source]#
+

Wait until the guild that matches the guild_id given at init is available (and the cache is ready).

+

The on_ready event is inadequate because it only waits 2 seconds for a GUILD_CREATE +gateway event before giving up and thus not populating the cache for unavailable guilds.

+
+
Return type:
+

None

+
+
+
+ +
+ +
+
+exception StartupError(base)[source]#
+

Bases: Exception

+

Exception class for startup errors.

+
+
+__init__(base)[source]#
+
+ +
+ +
+

Subpackages#

+ +
+
+

Submodules#

+ +
+
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.site_api.html b/v9.0.0/output/pydis_core.site_api.html new file mode 100644 index 00000000..858a36f8 --- /dev/null +++ b/v9.0.0/output/pydis_core.site_api.html @@ -0,0 +1,621 @@ + + + + + + + + + site_api - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

site_api#

+

An API wrapper around the Site API.

+
+
+class APIClient(site_api_url, site_api_token, **session_kwargs)[source]#
+

Bases: object

+

A wrapper for the Django Site API.

+
+
+__init__(site_api_url, site_api_token, **session_kwargs)[source]#
+

Initialize a new APIClient instance.

+
+
Parameters:
+
    +
  • site_api_url (str) – The URL of the site API.

  • +
  • site_api_token (str) – The token to use for authentication.

  • +
  • session_kwargs – Keyword arguments to pass to the aiohttp.ClientSession constructor.

  • +
+
+
+
+ +
+
+async close()[source]#
+

Close the aiohttp session.

+
+
Return type:
+

None

+
+
+
+ +
+
+async delete(endpoint, *, raise_for_status=True, **kwargs)[source]#
+

Send a DELETE request to the site API and return the JSON response.

+
+
Parameters:
+
    +
  • endpoint (str) – The endpoint to send the request to.

  • +
  • raise_for_status (bool) – Whether or not to raise an exception if the response is not OK.

  • +
  • **kwargs – Any extra keyword arguments to pass to aiohttp.request().

  • +
+
+
Return type:
+

Optional[dict]

+
+
Returns:
+

The JSON response the API returns, or None if the response is 204 No Content.

+
+
+
+ +
+
+async get(endpoint, *, raise_for_status=True, **kwargs)[source]#
+

Equivalent to APIClient.request() with GET passed as the method.

+
+
Return type:
+

dict

+
+
+
+ +
+
+async static maybe_raise_for_status(response, should_raise)[source]#
+

Raise ResponseCodeError for non-OK response if an exception should be raised.

+
+
Parameters:
+
+
+
Raises:
+

ResponseCodeError – If the response is not OK and should_raise is True.

+
+
Return type:
+

None

+
+
+
+ +
+
+async patch(endpoint, *, raise_for_status=True, **kwargs)[source]#
+

Equivalent to APIClient.request() with PATCH passed as the method.

+
+
Return type:
+

dict

+
+
+
+ +
+
+async post(endpoint, *, raise_for_status=True, **kwargs)[source]#
+

Equivalent to APIClient.request() with POST passed as the method.

+
+
Return type:
+

dict

+
+
+
+ +
+
+async put(endpoint, *, raise_for_status=True, **kwargs)[source]#
+

Equivalent to APIClient.request() with PUT passed as the method.

+
+
Return type:
+

dict

+
+
+
+ +
+
+async request(method, endpoint, *, raise_for_status=True, **kwargs)[source]#
+

Send an HTTP request to the site API and return the JSON response.

+
+
Parameters:
+
    +
  • method (str) – The HTTP method to use.

  • +
  • endpoint (str) – The endpoint to send the request to.

  • +
  • raise_for_status (bool) – Whether or not to raise an exception if the response is not OK.

  • +
  • **kwargs – Any extra keyword arguments to pass to aiohttp.request().

  • +
+
+
Return type:
+

dict

+
+
Returns:
+

The JSON response the API returns.

+
+
Raises:
+

ResponseCodeError – If the response is not OK and raise_for_status is True.

+
+
+
+ +
+ +
+
+exception ResponseCodeError(response, response_json=None, response_text=None)[source]#
+

Bases: ValueError

+

Raised in APIClient.request() when a non-OK HTTP response is received.

+
+
+__init__(response, response_json=None, response_text=None)[source]#
+

Initialize a new ResponseCodeError instance.

+
+
Parameters:
+
    +
  • response (aiohttp.ClientResponse) – The response object from the request.

  • +
  • response_json (Optional[dict]) – The JSON response returned from the request, if any.

  • +
  • response_text (Optional[str]) – The text of the request, if any.

  • +
+
+
+
+ +
+
+__str__()[source]#
+

Return a string representation of the error.

+
+ +
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.caching.html b/v9.0.0/output/pydis_core.utils.caching.html new file mode 100644 index 00000000..c25705dd --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.caching.html @@ -0,0 +1,487 @@ + + + + + + + + + caching - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

caching#

+

Utilities related to custom caches.

+
+
+class AsyncCache(max_size=128)[source]#
+

Bases: object

+

LRU cache implementation for coroutines.

+

Once the cache exceeds the maximum size, keys are deleted in FIFO order.

+

An offset may be optionally provided to be applied to the coroutine’s arguments when creating the cache key.

+
+
+__call__(arg_offset=0)[source]#
+

Decorator for async cache.

+
+
Parameters:
+

arg_offset (int) – The offset for the position of the key argument.

+
+
Return type:
+

Callable

+
+
Returns:
+

A decorator to wrap the target function.

+
+
+
+ +
+
+__init__(max_size=128)[source]#
+

Initialise a new AsyncCache instance.

+
+
Parameters:
+

max_size (int) – How many items to store in the cache.

+
+
+
+ +
+
+clear()[source]#
+

Clear cache instance.

+
+
Return type:
+

None

+
+
+
+ +
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.channel.html b/v9.0.0/output/pydis_core.utils.channel.html new file mode 100644 index 00000000..8f178335 --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.channel.html @@ -0,0 +1,483 @@ + + + + + + + + + channel - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

channel#

+

Useful helper functions for interacting with various discord channel objects.

+
+
+async get_or_fetch_channel(bot, channel_id)[source]#
+

Attempt to get or fetch the given channel_id from the bots cache, and return it.

+
+
Parameters:
+
+
+
Raises:
+
+
+
Return type:
+

GuildChannel

+
+
Returns:
+

The channel from the ID.

+
+
+
+ +
+
+is_in_category(channel, category_id)[source]#
+

Return whether the given channel in the the category with the id category_id.

+
+
Parameters:
+
    +
  • channel (TextChannel) – The channel to check.

  • +
  • category_id (int) – The category to check for.

  • +
+
+
Return type:
+

bool

+
+
Returns:
+

A bool depending on whether the channel is in the category.

+
+
+
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.commands.html b/v9.0.0/output/pydis_core.utils.commands.html new file mode 100644 index 00000000..fd8996f5 --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.commands.html @@ -0,0 +1,456 @@ + + + + + + + + + commands - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

commands#

+
+
+async clean_text_or_reply(ctx, text=None)[source]#
+

Cleans a text argument or replied message’s content.

+
+
Parameters:
+
    +
  • ctx (Context) – The command’s context

  • +
  • text (Optional[str]) – The provided text argument of the command (if given)

  • +
+
+
Raises:
+

discord.ext.commands.BadArgumenttext wasn’t provided and there’s no reply message / reply message content.

+
+
Return type:
+

str

+
+
Returns:
+

The cleaned version of text, if given, else replied message.

+
+
+
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.cooldown.html b/v9.0.0/output/pydis_core.utils.cooldown.html new file mode 100644 index 00000000..2e0dd82d --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.cooldown.html @@ -0,0 +1,506 @@ + + + + + + + + + cooldown - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

cooldown#

+

Helpers for setting a cooldown on commands.

+
+
+exception CommandOnCooldown(message, function, /, *args, **kwargs)[source]#
+

Bases: CommandError, Generic[P, R]

+

Raised when a command is invoked while on cooldown.

+
+
+__init__(message, function, /, *args, **kwargs)[source]#
+
+ +
+
+async call_without_cooldown()[source]#
+

Run the command this cooldown blocked.

+
+
Return type:
+

TypeVar(R)

+
+
Returns:
+

The command’s return value.

+
+
+
+ +
+ +
+
+P = ~P[source]#
+

The command’s signature.

+
+ +
+
+R[source]#
+

The command’s return value.

+

alias of TypeVar(‘R’)

+
+ +
+
+block_duplicate_invocations(*, cooldown_duration=5, send_notice=False, args_preprocessor=None)[source]#
+

Prevent duplicate invocations of a command with the same arguments in a channel for cooldown_duration seconds.

+
+
Parameters:
+
    +
  • cooldown_duration (float) – Length of the cooldown in seconds.

  • +
  • send_notice (bool) – If True, notify the user about the cooldown with a reply.

  • +
  • args_preprocessor (Optional[Callable[ParamSpec(P), Iterable[object]]]) – If specified, this function is called with the args and kwargs the function is called with, +its return value is then used to check for the cooldown instead of the raw arguments.

  • +
+
+
Return type:
+

Callable[Callable[ParamSpec(P), Awaitable[TypeVar(R)]], Callable[ParamSpec(P), Awaitable[TypeVar(R)]]]

+
+
Returns:
+

A decorator that adds a wrapper which applies the cooldowns.

+
+
+
+

Warning

+

The created wrapper raises CommandOnCooldown when the command is on cooldown.

+
+
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.function.html b/v9.0.0/output/pydis_core.utils.function.html new file mode 100644 index 00000000..1211ace3 --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.function.html @@ -0,0 +1,497 @@ + + + + + + + + + function - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

function#

+

Utils for manipulating functions.

+
+
+exception GlobalNameConflictError[source]#
+

Bases: Exception

+

Raised on a conflict between the globals used to resolve annotations of a wrapped function and its wrapper.

+
+ +
+
+command_wraps(wrapped, assigned=('__module__', '__name__', '__qualname__', '__doc__', '__annotations__'), updated=('__dict__',), *, ignored_conflict_names=frozenset({}))[source]#
+

Update the decorated function to look like wrapped, and update globals for discord.py forwardref evaluation.

+

See update_wrapper_globals() for more details on how the globals are updated.

+
+
Parameters:
+
    +
  • wrapped (Callable[ParamSpec(_P), TypeVar(_R)]) – The function to wrap with.

  • +
  • assigned (Sequence[str]) – Sequence of attribute names that are directly assigned from wrapped to wrapper.

  • +
  • updated (Sequence[str]) – Sequence of attribute names that are .update``d on ``wrapper from the attributes on wrapped.

  • +
  • ignored_conflict_names (Set[str]) – A set of names to ignore if a conflict between them is found.

  • +
+
+
Return type:
+

Callable[Callable[ParamSpec(_P), TypeVar(_R)], Callable[ParamSpec(_P), TypeVar(_R)]]

+
+
Returns:
+

A decorator that behaves like functools.wraps(), +with the wrapper replaced with the function update_wrapper_globals() returned.

+
+
+
+ +
+
+update_wrapper_globals(wrapper, wrapped, *, ignored_conflict_names=frozenset({}))[source]#
+

Create a copy of wrapper, the copy’s globals are updated with wrapped's globals.

+

For forwardrefs in command annotations, discord.py uses the __global__ attribute of the function +to resolve their values. This breaks for decorators that replace the function because they have +their own globals.

+
+

Warning

+

This function captures the state of wrapped's module’s globals when it’s called; +changes won’t be reflected in the new function’s globals.

+
+
+
Parameters:
+
+
+
Raises:
+

GlobalNameConflictError – If wrapper and wrapped share a global name that’s also used in wrapped's typehints, + and is not in ignored_conflict_names.

+
+
Return type:
+

Callable[ParamSpec(_P), TypeVar(_R)]

+
+
+
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.html b/v9.0.0/output/pydis_core.utils.html new file mode 100644 index 00000000..1717f802 --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.html @@ -0,0 +1,561 @@ + + + + + + + + + Pydis_Core Utils - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

Pydis_Core Utils#

+

Useful utilities and tools for Discord bot development.

+
+
+apply_monkey_patches()[source]#
+

Applies all common monkey patches for our bots.

+
+
Patches discord.ext.commands.Command and discord.ext.commands.Group to support root aliases.

A root_aliases keyword argument is added to these two objects, which is a sequence of alias names +that will act as top-level groups rather than being aliases of the command’s group.

+

It’s stored as an attribute also named root_aliases

+
+
Patches discord’s internal send_typing method so that it ignores 403 errors from Discord.

When under heavy load Discord has added a CloudFlare worker to this route, which causes 403 errors to be thrown.

+
+
+
+
Return type:
+

None

+
+
+
+ +
+
+unqualify(name)[source]#
+

Return an unqualified name given a qualified module/package name.

+
+
Parameters:
+

name (str) – The module name to unqualify.

+
+
Return type:
+

str

+
+
Returns:
+

The unqualified module name.

+
+
+
+ +
+

Submodules#

+ +
+
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.interactions.html b/v9.0.0/output/pydis_core.utils.interactions.html new file mode 100644 index 00000000..58a209fe --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.interactions.html @@ -0,0 +1,525 @@ + + + + + + + + + interactions - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

interactions#

+
+
+class DeleteMessageButton(*, style=<ButtonStyle.secondary: 2>, label='Delete', **kwargs)[source]#
+

Bases: Button

+

A button that can be added to a view to delete the message containing the view on click.

+

This button itself carries out no interaction checks, these should be done by the parent view.

+

See pydis_core.utils.interactions.ViewWithUserAndRoleCheck for a view that implements basic checks.

+
+
Parameters:
+
    +
  • style (ButtonStyle) – The style of the button, set to ButtonStyle.secondary if not specified.

  • +
  • label (str) – The label of the button, set to “Delete” if not specified.

  • +
+
+
+
+
+__init__(*, style=<ButtonStyle.secondary: 2>, label='Delete', **kwargs)[source]#
+
+ +
+
+async callback(interaction)[source]#
+

Delete the original message on button click.

+
+
Return type:
+

None

+
+
+
+ +
+ +
+
+class ViewWithUserAndRoleCheck(*, allowed_users, allowed_roles, timeout=180.0, message=None)[source]#
+

Bases: View

+

A view that allows the original invoker and moderators to interact with it.

+
+
Parameters:
+
    +
  • allowed_users (Sequence[int]) – A sequence of user’s ids who are allowed to interact with the view.

  • +
  • allowed_roles (Sequence[int]) – A sequence of role ids that are allowed to interact with the view.

  • +
  • timeout (Optional[float]) – Timeout in seconds from last interaction with the UI before no longer accepting input. +If None then there is no timeout.

  • +
  • message (Optional[Message]) – The message to remove the view from on timeout. This can also be set with +view.message = await ctx.send( ... )` , or similar, after the view is instantiated.

  • +
+
+
+
+
+__init__(*, allowed_users, allowed_roles, timeout=180.0, message=None)[source]#
+
+ +
+
+async interaction_check(interaction)[source]#
+

Ensure the user clicking the button is the view invoker, or a moderator.

+
+
Parameters:
+

interaction (Interaction) – The interaction that occurred.

+
+
Return type:
+

bool

+
+
+
+ +
+
+async on_timeout()[source]#
+

Remove the view from self.message if set.

+
+
Return type:
+

None

+
+
+
+ +
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.logging.html b/v9.0.0/output/pydis_core.utils.logging.html new file mode 100644 index 00000000..e4930894 --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.logging.html @@ -0,0 +1,484 @@ + + + + + + + + + logging - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

logging#

+

Common logging related functions.

+
+
+class CustomLogger(name, level=0)[source]#
+

Bases: Logger

+

Custom implementation of the logging.Logger class with an added trace method.

+
+
+trace(msg, *args, **kwargs)[source]#
+

Log the given message with the severity "TRACE".

+

To pass exception information, use the keyword argument exc_info with a true value:

+
logger.trace("Houston, we have an %s", "interesting problem", exc_info=1)
+
+
+
+
Parameters:
+
    +
  • msg (str) – The message to be logged.

  • +
  • args – Passed to the base log function as is.

  • +
  • kwargs – Passed to the base log function as is.

  • +
+
+
Return type:
+

None

+
+
+
+ +
+ +
+
+get_logger(name=None)[source]#
+

Utility to make mypy recognise that logger is of type CustomLogger.

+
+
Parameters:
+

name (Optional[str]) – The name given to the logger.

+
+
Return type:
+

CustomLogger

+
+
Returns:
+

An instance of the CustomLogger class.

+
+
+
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.members.html b/v9.0.0/output/pydis_core.utils.members.html new file mode 100644 index 00000000..c01f8e9f --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.members.html @@ -0,0 +1,469 @@ + + + + + + + + + members - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

members#

+

Useful helper functions for interactin with discord.Member objects.

+
+
+async get_or_fetch_member(guild, member_id)[source]#
+

Attempt to get a member from cache; on failure fetch from the API.

+
+
Return type:
+

Optional[Member]

+
+
Returns:
+

The discord.Member or None to indicate the member could not be found.

+
+
+
+ +
+
+async handle_role_change(member, coro, role)[source]#
+

Await the given coro with role as the sole argument.

+

Handle errors that we expect to be raised from +discord.Member.add_roles and discord.Member.remove_roles.

+
+
Parameters:
+
+
+
Return type:
+

None

+
+
+
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.regex.html b/v9.0.0/output/pydis_core.utils.regex.html new file mode 100644 index 00000000..104bbebf --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.regex.html @@ -0,0 +1,466 @@ + + + + + + + + + regex - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

regex#

+

Common regular expressions.

+
+
+DISCORD_INVITE[source]#
+

Regex for Discord server invites.

+
+

Warning

+

This regex pattern will capture until a whitespace, if you are to use the ‘invite’ capture group in +any HTTP requests or similar. Please ensure you sanitise the output using something +such as urllib.parse.quote().

+
+
+
+
+ +
+
+FORMATTED_CODE_REGEX[source]#
+

Regex for formatted code, using Discord’s code blocks.

+
+
+
+ +
+
+RAW_CODE_REGEX[source]#
+

Regex for raw code, not using Discord’s code blocks.

+
+
+
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file diff --git a/v9.0.0/output/pydis_core.utils.scheduling.html b/v9.0.0/output/pydis_core.utils.scheduling.html new file mode 100644 index 00000000..ea5620c8 --- /dev/null +++ b/v9.0.0/output/pydis_core.utils.scheduling.html @@ -0,0 +1,599 @@ + + + + + + + + + scheduling - Pydis Core v9.0.0 + + + + + + + + + + + + + + + + + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + + Back to top + +
+
+ +
+ +
+
+
+

scheduling#

+

Generic python scheduler.

+
+
+class Scheduler(name)[source]#
+

Bases: object

+

Schedule the execution of coroutines and keep track of them.

+

When instantiating a Scheduler, a name must be provided. This name is used to distinguish the +instance’s log messages from other instances. Using the name of the class or module containing +the instance is suggested.

+

Coroutines can be scheduled immediately with schedule or in the future with schedule_at +or schedule_later. A unique ID is required to be given in order to keep track of the +resulting Tasks. Any scheduled task can be cancelled prematurely using cancel by providing +the same ID used to schedule it.

+

The in operator is supported for checking if a task with a given ID is currently scheduled.

+

Any exception raised in a scheduled task is logged when the task is done.

+
+
+__contains__(task_id)[source]#
+

Return True if a task with the given task_id is currently scheduled.

+
+
Parameters:
+

task_id (Hashable) – The task to look for.

+
+
Return type:
+

bool

+
+
Returns:
+

True if the task was found.

+
+
+
+ +
+
+__init__(name)[source]#
+

Initialize a new Scheduler instance.

+
+
Parameters:
+

name (str) – The name of the Scheduler. Used in logging, and namespacing.

+
+
+
+ +
+
+cancel(task_id)[source]#
+

Unschedule the task identified by task_id. Log a warning if the task doesn’t exist.

+
+
Parameters:
+

task_id (Hashable) – The task’s unique ID.

+
+
Return type:
+

None

+
+
+
+ +
+
+cancel_all()[source]#
+

Unschedule all known tasks.

+
+
Return type:
+

None

+
+
+
+ +
+
+schedule(task_id, coroutine)[source]#
+

Schedule the execution of a coroutine.

+

If a task with task_id already exists, close coroutine instead of scheduling it. This +prevents unawaited coroutine warnings. Don’t pass a coroutine that’ll be re-used elsewhere.

+
+
Parameters:
+
    +
  • task_id (Hashable) – A unique ID to create the task with.

  • +
  • coroutine (Coroutine) – The function to be called.

  • +
+
+
Return type:
+

None

+
+
+
+ +
+
+schedule_at(time, task_id, coroutine)[source]#
+

Schedule coroutine to be executed at the given time.

+

If time is timezone aware, then use that timezone to calculate now() when subtracting. +If time is naïve, then use UTC.

+

If time is in the past, schedule coroutine immediately.

+

If a task with task_id already exists, close coroutine instead of scheduling it. This +prevents unawaited coroutine warnings. Don’t pass a coroutine that’ll be re-used elsewhere.

+
+
Parameters:
+
    +
  • time (datetime) – The time to start the task.

  • +
  • task_id (Hashable) – A unique ID to create the task with.

  • +
  • coroutine (Coroutine) – The function to be called.

  • +
+
+
Return type:
+

None

+
+
+
+ +
+
+schedule_later(delay, task_id, coroutine)[source]#
+

Schedule coroutine to be executed after delay seconds.

+

If a task with task_id already exists, close coroutine instead of scheduling it. This +prevents unawaited coroutine warnings. Don’t pass a coroutine that’ll be re-used elsewhere.

+
+
Parameters:
+
    +
  • delay (Union[int, float]) – How long to wait before starting the task.

  • +
  • task_id (Hashable) – A unique ID to create the task with.

  • +
  • coroutine (Coroutine) – The function to be called.

  • +
+
+
Return type:
+

None

+
+
+
+ +
+ +
+
+create_task(coro, *, suppressed_exceptions=(), event_loop=None, **kwargs)[source]#
+

Wrapper for creating an asyncio.Task which logs exceptions raised in the task.

+

If the event_loop kwarg is provided, the task is created from that event loop, +otherwise the running loop is used.

+
+
Parameters:
+
+
+
Returns:
+

The wrapped task.

+
+
Return type:
+

asyncio.Task

+
+
+
+ +
+ +
+
+ +
+ +
+
+ + + + + + + + + \ No newline at end of file -- cgit v1.2.3