Skip to content

callbacks

Callback utilities for ConfigDashboard.

Provides reusable patterns for authorization checks, error handling, and cache invalidation in callback functions.

Functions:

Classes

Functions

validate_author async

Python
validate_author(
    interaction: Interaction, author: User | Member, error_message: str
) -> bool

Validate that the interaction user is the authorized author.

Parameters:

  • interaction (Interaction) –

    The interaction to validate

  • author (User | Member) –

    The authorized author

  • error_message (str) –

    Error message to send if validation fails

Returns:

  • bool

    True if authorized, False otherwise

validate_interaction_data async

Python
validate_interaction_data(interaction: Interaction) -> bool

Validate that interaction has valid data.

Parameters:

  • interaction (Interaction) –

    The interaction to validate

Returns:

  • bool

    True if valid, False otherwise

handle_callback_error async

Python
handle_callback_error(
    interaction: Interaction, error: Exception, operation: str, context: str = ""
) -> None

Handle errors in callback functions with consistent error messages.

Parameters:

  • interaction (Interaction) –

    The interaction that triggered the error

  • error (Exception) –

    The exception that occurred

  • operation (str) –

    Description of the operation that failed

  • context (str, default: '' ) –

    Additional context for the error message

invalidate_and_rebuild async

Python
invalidate_and_rebuild(
    dashboard: ConfigDashboard,
    mode: str,
    rebuild_method: Callable[[], Awaitable[None]],
    interaction: Interaction,
) -> None

Invalidate cache, rebuild mode, and update message.

Parameters:

  • dashboard (ConfigDashboard) –

    The dashboard instance

  • mode (str) –

    The mode to rebuild

  • rebuild_method (Callable[[], Awaitable[None]]) –

    Async method to rebuild the mode

  • interaction (Interaction) –

    The interaction to update the message for

create_authorized_callback

Python
create_authorized_callback(
    dashboard: ConfigDashboard,
    callback_func: Callable[[Interaction], Awaitable[None]],
    unauthorized_message: str = "❌ You are not authorized to perform this action.",
) -> Callable[[Interaction], Awaitable[None]]

Wrap a callback function with authorization checks.

Parameters:

  • dashboard (ConfigDashboard) –

    The dashboard instance

  • callback_func (Callable[[Interaction], Awaitable[None]]) –

    The callback function to wrap

  • unauthorized_message (str, default: '❌ You are not authorized to perform this action.' ) –

    Message to send if user is not authorized

Returns:

create_role_update_callback

Python
create_role_update_callback(
    dashboard: ConfigDashboard, rank_value: int, rank_db_id: int
) -> Any

Create a callback for role selection that updates the database based on new state.

create_command_rank_callback

Python
create_command_rank_callback(dashboard: ConfigDashboard, command_name: str) -> Any

Create a callback for command rank assignment.

create_channel_callback

Python
create_channel_callback(dashboard: ConfigDashboard, option_key: str) -> Any

Create a callback for channel selection.

create_edit_rank_callback

Python
create_edit_rank_callback(
    dashboard: ConfigDashboard,
    rank_value: int,
    current_name: str,
    current_description: str | None,
) -> Any

Create a callback for editing a rank.

create_delete_rank_callback

Python
create_delete_rank_callback(
    dashboard: ConfigDashboard, rank_value: int, rank_name: str
) -> Any

Create a callback for deleting a rank.

create_cancel_assignment_callback

Python
create_cancel_assignment_callback() -> Any

Create callback for canceling role assignment.

create_confirm_assignment_callback

Python
create_confirm_assignment_callback(
    dashboard: ConfigDashboard,
    rank_id: int,
    rank_db_id: int,
    selected_roles: list[Role],
) -> Any

Create callback for confirming role assignment.

create_role_selection_callback

Python
create_role_selection_callback(
    dashboard: ConfigDashboard,
    rank_id: int,
    role_select: RoleSelect[LayoutView],
    assign_view: LayoutView,
    assign_container: Container[LayoutView],
    selected_roles: list[Role],
    confirm_callback: Any,
    cancel_callback: Any,
) -> Any

Create callback for role selection that updates the UI.