callbacks ¶
Callback utilities for ConfigDashboard.
Provides reusable patterns for authorization checks, error handling, and cache invalidation in callback functions.
Functions:
-
validate_author–Validate that the interaction user is the authorized author.
-
validate_interaction_data–Validate that interaction has valid data.
-
handle_callback_error–Handle errors in callback functions with consistent error messages.
-
invalidate_and_rebuild–Invalidate cache, rebuild mode, and update message.
-
create_authorized_callback–Wrap a callback function with authorization checks.
-
create_role_update_callback–Create a callback for role selection that updates the database based on new state.
-
create_command_rank_callback–Create a callback for command rank assignment.
-
create_channel_callback–Create a callback for channel selection.
-
create_edit_rank_callback–Create a callback for editing a rank.
-
create_delete_rank_callback–Create a callback for deleting a rank.
-
create_cancel_assignment_callback–Create callback for canceling role assignment.
-
create_confirm_assignment_callback–Create callback for confirming role assignment.
-
create_role_selection_callback–Create callback for role selection that updates the UI.
Classes¶
Functions¶
validate_author async ¶
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 ¶
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 ¶
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 ¶
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 ¶
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:
-
Callable[[Interaction], Awaitable[None]]–Wrapped callback with authorization checks
create_role_update_callback ¶
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 ¶
create_command_rank_callback(dashboard: ConfigDashboard, command_name: str) -> Any
Create a callback for command rank assignment.
create_channel_callback ¶
create_channel_callback(dashboard: ConfigDashboard, option_key: str) -> Any
Create a callback for channel selection.
create_edit_rank_callback ¶
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 ¶
create_delete_rank_callback(
dashboard: ConfigDashboard, rank_value: int, rank_name: str
) -> Any
Create a callback for deleting a rank.
create_cancel_assignment_callback ¶
create_cancel_assignment_callback() -> Any
Create callback for canceling role assignment.
create_confirm_assignment_callback ¶
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 ¶
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.