utils¶
Utilities to be used by the other modules.
Byte utilities.
- class byte_bot.lib.utils.PEPStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
StrEnumStatus of a PEP.
Note
ActiveandAcceptedboth traditionally useA, but are differentiated here for clarity.Based off of PEP Status in PEP1.
- class byte_bot.lib.utils.PEPType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
StrEnumType of PEP.
Based off of PEP Types in PEP1.
- byte_bot.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
- byte_bot.lib.utils.format_resolution_link(resolution: str | None) str[source]¶
Formats the resolution URL into a markdown link.
- byte_bot.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:
- byte_bot.lib.utils.get_next_friday(now: datetime, delay: int | None = None) tuple[datetime, datetime][source]¶
Calculate the next Friday from
now.If
delay, calculate the Friday fordelayweeks from now.- Parameters:
now – The current date and time.
delay – The number of weeks to delay the calculation.
- Returns:
The next Friday, optionally for the week after next.
- Return type:
datetime
- byte_bot.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.
- async byte_bot.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:
- async byte_bot.lib.utils.query_all_peps() list[PEP][source]¶
Query all PEPs from the PEPs Python.org API.
- async byte_bot.lib.utils.query_all_ruff_rules() list[RuffRule][source]¶
Query all Ruff linting rules.
- byte_bot.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:
- byte_bot.lib.utils.smart_chunk_text(text: str, max_size: int = 1000) list[str][source]¶
Split text into chunks without breaking markdown structures.
Respects markdown links, inline code, and code blocks. Prefers splitting at natural boundaries: paragraphs > sentences > newlines > spaces.
- Parameters:
text – The text to chunk.
max_size – Maximum characters per chunk (must be > 0).
- Returns:
List of text chunks.
- Raises:
ValueError – If max_size is not positive.