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:
-
GithubButton–Button view for GitHub repository links.
-
XkcdButtons–Button view for xkcd comic links.
-
EmbedCreator–Utility class for creating standardized Discord embeds.
-
EmbedType–Enumeration of available embed types with predefined styles.
-
ReportModal–Modal for submitting anonymous user reports.
-
BaseConfirmationView–Base confirmation view with confirm and cancel buttons.
-
ConfirmationDanger–Confirmation view with a danger button.
-
ConfirmationNormal–Confirmation view with a normal button.
-
TldrPaginatorView–Paginator view for navigating through long TLDR pages.
Classes¶
XkcdButtons ¶
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 ¶
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
titleordescriptionshould be provided. -
description(str, default:None) –The embed's main content. At least one of
titleordescriptionshould 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.
get_footer staticmethod ¶
get_footer(
bot: Tux | None = None,
user_name: str | None = None,
user_display_avatar: str | None = None,
) -> tuple[str, str | None]
ReportModal ¶
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 ¶
on_submit(interaction: Interaction) -> None
Send the report to the moderation team.
Parameters:
-
interaction(Interaction) –The interaction that triggered the command.
BaseConfirmationView ¶
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:
-
confirm–Handle the confirm button press.
-
cancel–Handle the cancel button press.
-
update_button_styles–Update button styles for the confirmation view.
Functions¶
confirm async ¶
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 ¶
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 ¶
update_button_styles() -> None
Update button styles for the confirmation view.
ConfirmationDanger ¶
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:
-
confirm–Handle the confirm button press.
-
cancel–Handle the cancel button press.
-
update_button_styles–Update button styles for the confirmation view.
Functions¶
confirm async ¶
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 ¶
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 ¶
update_button_styles() -> None
Update button styles for the confirmation view.
ConfirmationNormal ¶
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:
-
confirm–Handle the confirm button press.
-
cancel–Handle the cancel button press.
-
update_button_styles–Update button styles for the confirmation view.
Functions¶
confirm async ¶
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 ¶
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 ¶
update_button_styles() -> None
Update button styles for the confirmation view.
TldrPaginatorView ¶
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 ¶
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 ¶
on_timeout() -> None
Handle view timeout by removing the view from the message.
prev async ¶
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 ¶
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 ¶
update_message(interaction: Interaction) -> None
Update the message with the current page content.
Parameters:
-
interaction(Interaction) –The interaction to update the message for.