utils

Utilities to be used by the other modules.

Byte utilities.

class src.byte.lib.utils.BaseRuffRule[source]

Bases: TypedDict

Base Ruff rule data.

class src.byte.lib.utils.RuffRule[source]

Bases: dict

Ruff rule data.

class src.byte.lib.utils.FormattedRuffRule[source]

Bases: dict

Formatted Ruff rule data.

class src.byte.lib.utils.PEP[source]

Bases: TypedDict

PEP data.

Based off of the PEPS API.

src.byte.lib.utils.is_byte_dev() Check[Any][source]

Check if the user is a Byte developer.

Returns:

A check function.

src.byte.lib.utils.linker(title: str, link: str, show_embed: bool = False) str[source]

Create a Markdown link, optionally with an embed.

Parameters:
  • title – The title of the link.

  • link – The URL of the link.

  • show_embed – Whether to show the embed or not.

Returns:

A Markdown link.

src.byte.lib.utils.mention_user(user_id: int) str[source]

Mention a user by ID.

Parameters:

user_id – The unique identifier for the user.

Returns:

A formatted string that mentions the user.

src.byte.lib.utils.mention_user_nickname(user_id: int) str[source]

Mention a user by ID with a nickname.

Parameters:

user_id – The unique identifier for the user.

Returns:

A formatted string that mentions the user with a nickname.

src.byte.lib.utils.mention_channel(channel_id: int) str[source]

Mention a channel by ID.

Parameters:

channel_id – The unique identifier for the channel.

Returns:

A formatted string that mentions the channel.

src.byte.lib.utils.mention_role(role_id: int) str[source]

Mention a role by ID.

Parameters:

role_id – The unique identifier for the role.

Returns:

A formatted string that mentions the role.

src.byte.lib.utils.mention_slash_command(name: str, command_id: int) str[source]

Mention a slash command by name and ID.

Parameters:
  • name – The name of the slash command.

  • command_id – The unique identifier for the slash command.

Returns:

A formatted string that mentions the slash command.

src.byte.lib.utils.mention_custom_emoji(name: str, emoji_id: int) str[source]

Mention a custom emoji by name and ID.

Parameters:
  • name – The name of the emoji.

  • emoji_id – The unique identifier for the emoji.

Returns:

A formatted string that mentions the custom emoji.

src.byte.lib.utils.mention_custom_emoji_animated(name: str, emoji_id: int) str[source]

Mention an animated custom emoji by name and ID.

Parameters:
  • name – The name of the animated emoji.

  • emoji_id – The unique identifier for the animated emoji.

Returns:

A formatted string that mentions the animated custom emoji.

src.byte.lib.utils.mention_timestamp(timestamp: int, style: str = '') str[source]

Mention a timestamp, optionally with a style.

Parameters:
  • timestamp – The Unix timestamp to format.

  • style – An optional string representing the timestamp style. (Default `` , valid styles: ``t, T, d, D, f, F, R)

Returns:

A formatted string that represents the timestamp.

src.byte.lib.utils.mention_guild_navigation(guild_nav_type: str, guild_element_id: int) str[source]

Mention a guild navigation element by type and ID.

Parameters:
  • guild_nav_type – The type of the guild navigation element.

  • guild_element_id – The unique identifier for the element.

Returns:

A formatted string that mentions the guild navigation element.

src.byte.lib.utils.format_ruff_rule(rule_data: RuffRule) FormattedRuffRule[source]

Format ruff rule data for embed-friendly output and append rule link.

Parameters:

rule_data – The ruff rule data.

Returns:

The formatted rule data.

Return type:

FormattedRuffRule

async src.byte.lib.utils.query_all_ruff_rules() list[RuffRule][source]

Query all Ruff linting rules.

Returns:

All ruff rules

Return type:

list[RuffRule]

src.byte.lib.utils.run_ruff_format(code: str) str[source]

Formats code using Ruff.

Parameters:

code – The code to format.

Returns:

The formatted code.

Return type:

str

async src.byte.lib.utils.paste(code: str) str[source]

Uploads the given code to paste.pythondiscord.com.

Parameters:

code – The formatted code to upload.

Returns:

The URL of the uploaded paste.

Return type:

str

src.byte.lib.utils.chunk_sequence(sequence: Iterable[_T], size: int) Iterable[tuple[_T, ...]][source]

Naïve chunking of an iterable.

Parameters:
  • sequence (Iterable[_T]) – Iterable to chunk

  • size (int) – Size of chunk

Yields:

Iterable[tuple[_T, …]] – An n-tuple that contains chunked data

async src.byte.lib.utils.query_all_peps() list[PEP][source]

Query all PEPs from the PEPs Python.org API.

Returns:

All PEPs

Return type:

list[PEP]