Skip to content

mail

Mail Plugin for Tux Bot.

This plugin provides email account management functionality for the ATL Discord server, allowing administrators to create and manage email accounts through the Mailcow API.

Classes:

  • Mail

    Mail plugin for managing email accounts via Mailcow API.

Functions:

  • setup

    Set up the mail plugin.

Classes

Mail

Python
Mail(bot: Tux)

Bases: BaseCog

Mail plugin for managing email accounts via Mailcow API.

Initialize the Mail plugin.

Parameters:

  • bot (Tux) –

    The bot instance to initialize the plugin with.

Methods:

  • register

    Register a user for mail.

  • get_config

    Get a configuration value from CONFIG with support for nested keys.

  • __repr__

    Return a string representation of the cog instance.

  • unload_if_missing_config

    Check if required configuration is missing and log warning.

Attributes:

Attributes

db property

Get the database coordinator for accessing database controllers.

Returns:

  • DatabaseCoordinator

    Coordinator providing access to all database controllers.

Examples:

Python Console Session
>>> await self.db.guild_config.get_guild_config(guild_id)
>>> await self.db.cases.create_case(...)
Notes

This property provides convenient access to database operations without needing to access self.bot.db directly.

Functions

register async
Python
register(interaction: Interaction, member: Member, username: str) -> None

Register a user for mail.

Parameters:

  • interaction (Interaction) –

    The interaction object for the command.

  • member (Member) –

    The member to register for mail.

  • username (str) –

    The username to register for mail.

_setup_command_usage
Python
_setup_command_usage() -> None

Generate usage strings for all commands in this cog that lack explicit usage.

The generated usage follows the pattern: <qualified_name> <param tokens>

Where: - Required parameters are denoted as <name: Type> - Optional parameters are denoted as [name: Type] - The prefix is intentionally omitted (provided by ctx.prefix)

Examples:

ban <member: Member> [reason: str] config set <key: str> <value: str>

Notes

Respects explicit usage strings if already set on a command. Errors during generation are logged but don't prevent cog loading.

_generate_usage
Python
_generate_usage(command: Command[Any, ..., Any]) -> str

Generate a usage string with support for flags and positional parameters.

This method inspects the command's callback signature to detect: - FlagConverter parameters (e.g., --flag value) - Positional parameters (e.g., <required> or [optional])

Parameters:

  • command (Command) –

    The command to generate usage for.

Returns:

  • str

    Generated usage string, or qualified command name as fallback.

Notes

Delegates to shared usage generator for consistency across all cogs. Falls back gracefully to command name if generation fails.

_generate_password staticmethod
Python
_generate_password() -> str

Generate a random password for the mailbox.

Returns:

  • str

    The generated password.

_prepare_mailbox_data
Python
_prepare_mailbox_data(username: str, password: str, member_id: int) -> MailboxData

Prepare the mailbox data for the API request.

Parameters:

  • username (str) –

    The username to register for mail.

  • password (str) –

    The password to register for mail.

  • member_id (int) –

    The ID of the member to register for mail.

Returns:

  • MailboxData

    The prepared mailbox data dictionary.

_handle_response async
Python
_handle_response(
    interaction: Interaction, response: Response, member: Member, password: str
) -> None

Handle the response from the API request.

Parameters:

  • interaction (Interaction) –

    The interaction object for the command.

  • response (Response) –

    The response from the API request.

  • member (Member) –

    The member to register for mail.

  • password (str) –

    The password to register for mail.

get_config
Python
get_config(key: str, default: Any = None) -> Any

Get a configuration value from CONFIG with support for nested keys.

Parameters:

  • key (str) –

    The configuration key to retrieve. Supports dot notation for nested values (e.g., "BOT_INFO.BOT_NAME").

  • default (Any, default: None ) –

    Default value to return if key is not found, by default None.

Returns:

  • Any

    The configuration value or default if not found.

Examples:

Python Console Session
>>> self.get_config("BOT_INFO.BOT_NAME")
'Tux'
>>> self.get_config("MISSING_KEY", "fallback")
'fallback'
Notes

Errors during retrieval are logged but don't raise exceptions. Returns the default value on any error.

_extract_mailbox_info staticmethod
Python
_extract_mailbox_info(result: list[dict[str, str | None]]) -> str | None

Extract the mailbox information from the response.

Parameters:

  • result (list[dict[str, str | None]]) –

    The response from the API request.

Returns:

  • str | None

    The mailbox information.

__repr__
Python
__repr__() -> str

Return a string representation of the cog instance.

Returns:

  • str

    String representation in format <CogName bot=BotUser>.

_send_dm async staticmethod
Python
_send_dm(
    interaction: Interaction, member: Member, mailbox_info: str, password: str
) -> None

Send a DM to the member with the mailbox information.

Parameters:

  • interaction (Interaction) –

    The interaction object for the command.

  • member (Member) –

    The member to send the DM to.

  • mailbox_info (str) –

    The mailbox information to send to the member.

  • password (str) –

    The password to send to the member.

unload_if_missing_config
Python
unload_if_missing_config(condition: bool, config_name: str) -> bool

Check if required configuration is missing and log warning.

This allows cogs to detect missing configuration at load time and return early from init to prevent partial initialization.

Parameters:

  • condition (bool) –

    True if config is missing (should unload), False otherwise.

  • config_name (str) –

    Name of the missing configuration for logging purposes.

Returns:

  • bool

    True if config is missing (caller should return early), False if config is present.

Examples:

Python Console Session
>>> def __init__(self, bot: Tux):
...     super().__init__(bot)
...     if self.unload_if_missing_config(not CONFIG.GITHUB_TOKEN, "GITHUB_TOKEN"):
...         return  # Exit early, cog will be partially loaded but won't register commands
...     self.github_client = GitHubClient()
Notes

When this returns True, the cog's init should return early to avoid initializing services that depend on the missing config. The cog will be loaded but commands won't be registered properly, preventing runtime errors.

For complete cog unloading, the bot owner should remove the cog from the modules directory or use the reload system to unload it programmatically.

_unload_self async
Python
_unload_self(extension_name: str) -> None

Perform the actual cog unload operation.

Parameters:

  • extension_name (str) –

    Full extension name to unload.

Notes

This is called as a background task by unload_if_missing_config(). Errors during unload are logged but don't raise exceptions.

Functions

setup async

Python
setup(bot: Tux) -> None

Set up the mail plugin.

Parameters:

  • bot (Tux) –

    The bot instance to add the cog to.