Skip to content

checks

Dynamic Permission System - Fully Database-Driven.

This module provides dynamic permission decorators with ZERO hardcoded opinions. All permission requirements are stored in the database and configured per-guild.

Usage: @requires_command_permission() # 100% dynamic, reads from database async def ban(self, ctx, user): ...

Configuration: Guilds configure permissions via /config permission commands. Without configuration, commands are denied by default (secure).

Classes:

Functions:

Classes

TuxPermissionDeniedError

Python
TuxPermissionDeniedError(
    required_rank: int, user_rank: int, command_name: str | None = None
)

Bases: TuxPermissionError

Raised when a user doesn't have permission to run a command (dynamic system).

Initialize the permission denied error.

Parameters:

  • required_rank (int) –

    The minimum permission rank required to run the command.

  • user_rank (int) –

    The actual permission rank of the user.

  • command_name (str, default: None ) –

    The name of the command that was attempted, by default None.

Functions

Functions

requires_command_permission

Python
requires_command_permission(*, allow_unconfigured: bool = False) -> Callable[[F], F]

Provide dynamic, database-driven command permissions.

This decorator provides fully dynamic permission checking that reads required permission ranks from the database per guild. Commands are denied by default if not configured (safe mode).

Parameters:

  • allow_unconfigured (bool, default: False ) –

    If True, allow commands without database configuration. If False (default), deny unconfigured commands.

Returns:

  • Callable[[F], F]

    The decorated function with permission checking.

get_permission_system

Python
get_permission_system() -> PermissionSystem

Get the global permission system instance.

Returns:

Raises:

  • RuntimeError

    If the permission system hasn't been initialized yet.

Notes

Call init_permission_system() during bot startup before using this.

init_permission_system

Python
init_permission_system(bot: Tux, db: DatabaseCoordinator) -> PermissionSystem

Initialize the global permission system instance.

This should be called once during bot startup, after database initialization.

Parameters:

Returns:

Notes

Uses module-level attribute assignment to avoid global statement warning.