Skip to content

ui

UI components for the Tux Discord bot.

This module contains all user interface components including: - Embeds and embed creators - Buttons and interactive components - Views for complex interactions - Modals for user input - Help system components

Modules:

  • banner

    Banner creation and formatting utilities for Tux.

  • buttons

    Discord UI Button Components for Tux Bot.

  • embeds

    Discord Embed Creation Utilities for Tux Bot.

  • modals

    Modal components for Discord UI interactions.

  • views

    View components for Discord UI interactions.

Classes:

Classes

GithubButton

Python
GithubButton(url: str)

Bases: View

Button view for GitHub repository links.

Initialize GitHub button with repository URL.

Parameters:

  • url (str) –

    URL to the GitHub repository or issue.

Functions

XkcdButtons

Python
XkcdButtons(explain_url: str, webpage_url: str)

Bases: View

Button view for xkcd comic links.

Initialize xkcd buttons with explain and webpage links.

Parameters:

  • explain_url (str) –

    URL to the explainxkcd page for the comic.

  • webpage_url (str) –

    URL to the original xkcd webpage.

Functions

EmbedCreator

Utility class for creating standardized Discord embeds.

Methods:

  • create_embed

    Create a customized Discord embed based on the specified type and parameters.

  • get_footer

    Generate footer text and icon for embeds.

Functions

create_embed staticmethod
Python
create_embed(
    embed_type: EmbedType,
    bot: Tux | None = None,
    title: str | None = None,
    description: str | None = None,
    user_name: str | None = None,
    user_display_avatar: str | None = None,
    image_url: str | None = None,
    thumbnail_url: str | None = None,
    message_timestamp: datetime | None = None,
    custom_footer_text: str | None = None,
    custom_footer_icon_url: str | None = None,
    custom_author_text: str | None = None,
    custom_author_text_url: str | None = None,
    custom_author_icon_url: str | None = None,
    custom_color: int | Colour | None = None,
    hide_author: bool = False,
    hide_timestamp: bool = False,
) -> Embed

Create a customized Discord embed based on the specified type and parameters.

Parameters:

  • embed_type (EmbedType) –

    Determines the default color and icon for the embed.

  • bot (Tux, default: None ) –

    If provided, used to display bot latency in the footer.

  • title (str, default: None ) –

    The embed's title. At least one of title or description should be provided.

  • description (str, default: None ) –

    The embed's main content. At least one of title or description should be provided.

  • user_name (str, default: None ) –

    Used in footer if provided, otherwise defaults to bot's username.

  • user_display_avatar (str, default: None ) –

    User's avatar URL for the footer icon.

  • image_url (str, default: None ) –

    URL for the embed's main image.

  • thumbnail_url (str, default: None ) –

    URL for the embed's thumbnail image.

  • message_timestamp (datetime, default: None ) –

    Custom timestamp for the embed.

  • custom_footer_text (str, default: None ) –

    Overrides default footer text if provided.

  • custom_footer_icon_url (str, default: None ) –

    Overrides default footer icon if provided.

  • custom_author_text (str, default: None ) –

    Overrides default author text if provided.

  • custom_author_text_url (str, default: None ) –

    Adds author URL if provided.

  • custom_author_icon_url (str, default: None ) –

    Overrides default author icon if provided.

  • hide_author (bool, default: False ) –

    If True, removes the author from the embed.

  • custom_color (int or Colour, default: None ) –

    Overrides default color for the embed type if provided.

Returns:

  • Embed

    The customized Discord embed.

Python
get_footer(
    bot: Tux | None = None,
    user_name: str | None = None,
    user_display_avatar: str | None = None,
) -> tuple[str, str | None]

Generate footer text and icon for embeds.

Parameters:

  • bot (Tux, default: None ) –

    The bot instance to get latency from.

  • user_name (str, default: None ) –

    Username to include in footer.

  • user_display_avatar (str, default: None ) –

    User avatar URL for footer icon.

Returns:

  • tuple[str, str | None]

    Tuple of (footer_text, avatar_url).

EmbedType

Bases: Enum

Enumeration of available embed types with predefined styles.

ReportModal

Python
ReportModal(*, title: str = 'Submit an anonymous report', bot: Tux)

Bases: Modal

Modal for submitting anonymous user reports.

Initialize the report modal.

Parameters:

  • title (str, default: 'Submit an anonymous report' ) –

    The modal title, by default "Submit an anonymous report".

  • bot (Tux) –

    The bot instance to use for database access and operations.

Raises:

  • RuntimeError

    If DatabaseService is not available via DI.

Methods:

  • on_submit

    Send the report to the moderation team.

Functions

on_submit async
Python
on_submit(interaction: Interaction) -> None

Send the report to the moderation team.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered the command.

BaseConfirmationView

Python
BaseConfirmationView(user: int)

Bases: View

Base confirmation view with confirm and cancel buttons.

Initialize the base confirmation view.

Parameters:

  • user (int) –

    The user ID that can interact with this view.

Methods:

Functions

confirm async
Python
confirm(interaction: Interaction, button: Button[View]) -> None

Handle the confirm button press.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered this action.

  • button (Button[View]) –

    The button that was pressed.

cancel async
Python
cancel(interaction: Interaction, button: Button[View]) -> None

Handle the cancel button press.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered this action.

  • button (Button[View]) –

    The button that was pressed.

update_button_styles
Python
update_button_styles() -> None

Update button styles for the confirmation view.

ConfirmationDanger

Python
ConfirmationDanger(user: int)

Bases: BaseConfirmationView

Confirmation view with a danger button.

Initialize the danger confirmation view.

Parameters:

  • user (int) –

    The user ID that can interact with this view.

Methods:

Functions

confirm async
Python
confirm(interaction: Interaction, button: Button[View]) -> None

Handle the confirm button press.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered this action.

  • button (Button[View]) –

    The button that was pressed.

cancel async
Python
cancel(interaction: Interaction, button: Button[View]) -> None

Handle the cancel button press.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered this action.

  • button (Button[View]) –

    The button that was pressed.

update_button_styles
Python
update_button_styles() -> None

Update button styles for the confirmation view.

ConfirmationNormal

Python
ConfirmationNormal(user: int)

Bases: BaseConfirmationView

Confirmation view with a normal button.

Initialize the normal confirmation view.

Parameters:

  • user (int) –

    The user ID that can interact with this view.

Methods:

Functions

confirm async
Python
confirm(interaction: Interaction, button: Button[View]) -> None

Handle the confirm button press.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered this action.

  • button (Button[View]) –

    The button that was pressed.

cancel async
Python
cancel(interaction: Interaction, button: Button[View]) -> None

Handle the cancel button press.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered this action.

  • button (Button[View]) –

    The button that was pressed.

update_button_styles
Python
update_button_styles() -> None

Update button styles for the confirmation view.

TldrPaginatorView

Python
TldrPaginatorView(pages: list[str], title: str, user: User, bot: Tux)

Bases: View

Paginator view for navigating through long TLDR pages.

Initialize the TLDR paginator view.

Parameters:

  • pages (list[str]) –

    List of page content strings to paginate through.

  • title (str) –

    Title for the paginated content.

  • user (User) –

    User who can interact with this view.

  • bot (Tux) –

    Bot instance for embed creation.

Methods:

  • interaction_check

    Check if the interaction user is allowed to interact with this view.

  • on_timeout

    Handle view timeout by removing the view from the message.

  • prev

    Navigate to the previous page.

  • next

    Navigate to the next page.

  • update_message

    Update the message with the current page content.

Functions

interaction_check async
Python
interaction_check(interaction: Interaction) -> bool

Check if the interaction user is allowed to interact with this view.

Parameters:

  • interaction (Interaction) –

    The interaction to check.

Returns:

  • bool

    True if the user is allowed to interact.

on_timeout async
Python
on_timeout() -> None

Handle view timeout by removing the view from the message.

prev async
Python
prev(interaction: Interaction, button: Button[View])

Navigate to the previous page.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered this action.

  • button (Button[View]) –

    The button that was pressed.

next async
Python
next(interaction: Interaction, button: Button[View])

Navigate to the next page.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered this action.

  • button (Button[View]) –

    The button that was pressed.

update_message async
Python
update_message(interaction: Interaction) -> None

Update the message with the current page content.

Parameters:

  • interaction (Interaction) –

    The interaction to update the message for.