Skip to content

moderation_coordinator

Moderation coordinator service.

Orchestrates all moderation services and provides the main interface for moderation operations, replacing the mixin-based approach.

Classes:

Classes

ModerationCoordinator

Python
ModerationCoordinator(
    case_service: CaseService,
    communication_service: CommunicationService,
    execution_service: ExecutionService,
)

Main coordinator for moderation operations.

Orchestrates case creation, communication, and execution using proper service composition instead of mixins.

Initialize the moderation coordinator.

Parameters:

Methods:

Functions

execute_moderation_action async
Python
execute_moderation_action(
    ctx: Context[Tux],
    case_type: CaseType,
    user: Member | User,
    reason: str,
    silent: bool = False,
    dm_action: str | None = None,
    actions: Sequence[tuple[Callable[..., Coroutine[Any, Any, Any]], type[Any]]]
    | None = None,
    duration: int | None = None,
    expires_at: datetime | None = None,
    **extra_case_data: Any,
) -> Case | None

Execute a complete moderation action.

This method orchestrates the entire moderation flow: 1. Validate permissions and inputs 2. Send DM if required (before action for removal actions) 3. Execute Discord actions with retry logic 4. Create database case 5. Send DM if required (after action for non-removal actions) 6. Send response embed to the moderator 7. Send response embed to the log channel 8. Update the case audit log message ID

Parameters:

  • ctx (Context[Tux]) –

    Command context.

  • case_type (CaseType) –

    Type of moderation action.

  • user (Member | User) –

    Target user.

  • reason (str) –

    Reason for the action.

  • silent (bool, default: False ) –

    Whether to send DM to user, by default False.

  • dm_action (str | None, default: None ) –

    Custom DM action description, by default None.

  • actions (Sequence[tuple[Callable[..., Coroutine[Any, Any, Any]], type[Any]]] | None, default: None ) –

    Discord API actions to execute, by default None.

  • duration (int | None, default: None ) –

    Duration for temp actions, by default None.

  • expires_at (datetime | None, default: None ) –

    Expiration timestamp for temp actions, by default None.

  • **extra_case_data (Any, default: {} ) –

    Additional case data fields.

Returns:

  • Case | None

    The created case, or None if case creation failed.

_handle_dm_timing async
Python
_handle_dm_timing(
    ctx: Context[Tux],
    case_type: CaseType,
    user: Member | User,
    reason: str,
    action_desc: str,
    silent: bool,
) -> bool

Handle DM timing based on action type.

Returns:

  • True if DM was sent, False otherwise
_execute_actions async
Python
_execute_actions(
    ctx: Context[Tux],
    case_type: CaseType,
    user: Member | User,
    actions: Sequence[tuple[Callable[..., Coroutine[Any, Any, Any]], type[Any]]],
) -> list[Any]

Execute Discord API actions.

Note: Error handling is now centralized in the error handler. Exceptions are allowed to bubble up to be properly handled by the centralized error handler, which provides: - Consistent error messaging - Proper Sentry integration with command context - Guild/user context enrichment - Transaction management

Returns:

  • List of action results
_handle_post_action_dm async
Python
_handle_post_action_dm(
    ctx: Context[Tux], user: Member | User, reason: str, action_desc: str
) -> bool

Handle DM sending after successful action execution.

Returns:

  • True if DM was sent, False otherwise
_send_response_embed async
Python
_send_response_embed(
    ctx: Context[Tux], case: Case | None, user: Member | User, dm_sent: bool
) -> None

Send the response embed for the moderation action.

_send_mod_log_embed async
Python
_send_mod_log_embed(
    ctx: Context[Tux], case: Case, user: Member | User, dm_sent: bool
) -> Message | None

Send the response embed to the mod log channel.

_get_default_dm_action
Python
_get_default_dm_action(case_type: CaseType) -> str

Get the default DM action description for a case type.

Returns:

  • str

    Default action description for the case type.