models ¶
Database Models for Tux Bot.
This module contains all SQLModel-based database models used by the Tux Discord bot, including base classes, mixins, enums, and specific model classes for various features like moderation, levels, snippets, and guild configuration.
Modules:
-
base–Base Database Models for Tux Bot.
-
enums–Database model enums for Tux bot.
-
models–Database Models for Tux Bot.
Classes:
-
BaseModel–Base SQLModel class with automatic timestamp management.
-
SoftDeleteMixin–Mixin for soft delete functionality.
-
UUIDMixin–Mixin for models that need UUID primary keys.
-
CaseType–Types of moderation cases that can be recorded in the system.
-
PermissionType–Types of permissions that can be configured in the system.
-
AFK–Away From Keyboard status for users.
-
Case–Moderation case records.
-
Guild–Discord guild/server model with metadata and relationships.
-
GuildConfig–Guild-specific configuration settings.
-
Levels–User experience and leveling data.
-
PermissionAssignment–Assigns permission ranks to Discord roles in each server.
-
PermissionCommand–Assigns permission requirements to specific commands.
-
PermissionRank–Permission ranks for guild role-based access control.
-
Reminder–Scheduled reminders for users.
-
Snippet–Custom command snippets for guilds.
-
Starboard–Starboard configuration for guilds.
-
StarboardMessage–Messages that have been starred on the starboard.
Classes¶
BaseModel ¶
Bases: SQLModel, TimestampMixin
Base SQLModel class with automatic timestamp management.
This class provides automatic created_at and updated_at timestamp fields that are managed by the database, along with serialization utilities for JSON responses.
Attributes:
-
created_at((datetime, optional)) –Timestamp when the record was created (database-managed).
-
updated_at((datetime, optional)) –Timestamp when the record was last updated (database-managed).
Methods:
-
serialize_datetimes–Serialize datetime objects to ISO format strings.
-
model_post_init–Ensure timestamp fields are always present in dict for compatibility.
-
to_dict–Convert model instance to dictionary with relationship support.
Functions¶
serialize_datetimes ¶
model_post_init ¶
model_post_init(__context: Any) -> None
Ensure timestamp fields are always present in dict for compatibility.
Even though timestamps are database-managed, some SQLAlchemy operations expect these fields to be accessible in the model's dict. This ensures compatibility without interfering with database defaults.
to_dict ¶
to_dict(
include_relationships: bool = False, relationships: list[str] | None = None
) -> dict[str, Any]
Convert model instance to dictionary with relationship support.
Parameters:
-
include_relationships(bool, default:False) –Whether to include relationship fields, by default False.
-
relationships(list[str] | None, default:None) –Specific relationships to include (if None, includes all), by default None.
Returns:
SoftDeleteMixin ¶
Bases: SQLModel
Mixin for soft delete functionality.
Provides: - deleted_at: Timestamp when record was soft-deleted - is_deleted: Boolean flag for soft delete status
Methods:
-
serialize_deleted_at–Serialize deleted_at field to ISO format string.
-
soft_delete–Mark record as soft-deleted.
-
restore–Restore a soft-deleted record.
UUIDMixin ¶
Bases: SQLModel
Mixin for models that need UUID primary keys.
Provides: - id: UUID primary key with auto-generation - Proper indexing for performance
CaseType ¶
Types of moderation cases that can be recorded in the system.
-
ban ClassesBan Functionsmoderate_user -
case_service ClassesCaseService Functionscreate_case -
cases ClassesCases Functionsmoderate_user -
execution_service ClassesExecutionService Functionsget_operation_type -
jail ClassesJail Functionsmoderate_user -
kick ClassesKick Functionsmoderate_user -
moderation ClassesModerationCogBase Functionsmoderate_user -
moderation Classes -
moderation_coordinator ClassesModerationCoordinator Functions -
poll ClassesPoll Functionsmoderate_user -
pollban ClassesPollBan Functionsmoderate_user -
pollunban ClassesPollUnban Functionsmoderate_user -
snippetban ClassesSnippetBan Functionsmoderate_user -
snippetunban ClassesSnippetUnban Functionsmoderate_user -
tempban ClassesTempBan Functionsmoderate_user -
timeout ClassesTimeout Functionsmoderate_user -
unban ClassesUnban Functionsmoderate_user -
unjail ClassesUnjail Functionsmoderate_user -
untimeout ClassesUntimeout Functionsmoderate_user -
warn ClassesWarn Functionsmoderate_user
AFK ¶
Bases: SQLModel
Away From Keyboard status for users.
Tracks when users set themselves as AFK and provides a reason for their absence.
Attributes:
-
member_id(int) –Discord user ID (primary key).
-
guild_id(int) –Guild ID (primary key, foreign key to guild table).
-
nickname(str) –User's nickname when they went AFK.
-
reason(str) –Reason for being AFK.
-
since(datetime) –When the user went AFK.
-
until((datetime, optional)) –When the AFK status expires (for scheduled AFK).
-
enforced(bool) –Whether AFK is enforced (user can't remove it themselves).
-
perm_afk(bool) –Whether this is a permanent AFK status.
Methods:
-
__repr__–Return string representation showing member and guild.
Case ¶
Bases: BaseModel
Moderation case records.
Represents individual moderation actions taken against users, such as bans, kicks, timeouts, warnings, etc.
Attributes:
-
id(int) –Unique case identifier for the guild.
-
case_status(bool) –Whether the case is valid or voided.
-
case_processed(bool) –Whether expiration has been processed.
-
case_type(CaseType) –Type of moderation action taken.
-
case_reason(str) –Reason for the moderation action.
-
case_moderator_id(int) –Discord user ID of the moderator who took action.
-
case_user_id(int) –Discord user ID of the moderated user.
-
case_user_roles(list[int]) –User's roles at the time of the case.
-
case_number((int, optional)) –Sequential case number for the guild.
-
case_expires_at((datetime, optional)) –When temporary action expires.
-
case_metadata((dict, optional)) –Additional case-specific metadata.
-
mod_log_message_id((int, optional)) –Discord message ID in mod log.
-
guild_id(int) –Discord guild ID where the case occurred.
-
case ClassesCaseController Functions-
close_case -
create_case -
get_active_cases_by_user -
get_all_cases -
get_case_by_id -
get_case_by_number -
get_cases_by_guild -
get_cases_by_moderator -
get_cases_by_options -
get_cases_by_type -
get_cases_by_user -
get_expired_cases -
get_expired_tempbans -
get_latest_case_by_user -
get_recent_cases -
update_case -
update_case_by_number -
update_mod_log_message_id
-
-
case_service ClassesCaseService Functions -
controllers ClassesCaseController Functions-
close_case -
create_case -
get_active_cases_by_user -
get_all_cases -
get_case_by_id -
get_case_by_number -
get_cases_by_guild -
get_cases_by_moderator -
get_cases_by_options -
get_cases_by_type -
get_cases_by_user -
get_expired_cases -
get_expired_tempbans -
get_latest_case_by_user -
get_recent_cases -
update_case -
update_case_by_number -
update_mod_log_message_id
-
-
exceptions Functionshandle_case_result -
moderation Classes -
moderation_coordinator ClassesModerationCoordinator Functionsexecute_moderation_action -
unjail ClassesUnjail Functionsget_latest_jail_case
Methods:
-
__repr__–Return string representation showing guild, case number, type and target user.
-
serialize_datetimes–Serialize datetime objects to ISO format strings.
-
model_post_init–Ensure timestamp fields are always present in dict for compatibility.
-
to_dict–Convert model instance to dictionary with relationship support.
Functions¶
__repr__ ¶
__repr__() -> str
Return string representation showing guild, case number, type and target user.
serialize_datetimes ¶
model_post_init ¶
model_post_init(__context: Any) -> None
Ensure timestamp fields are always present in dict for compatibility.
Even though timestamps are database-managed, some SQLAlchemy operations expect these fields to be accessible in the model's dict. This ensures compatibility without interfering with database defaults.
to_dict ¶
to_dict(
include_relationships: bool = False, relationships: list[str] | None = None
) -> dict[str, Any]
Convert model instance to dictionary with relationship support.
Parameters:
-
include_relationships(bool, default:False) –Whether to include relationship fields, by default False.
-
relationships(list[str] | None, default:None) –Specific relationships to include (if None, includes all), by default None.
Returns:
Guild ¶
Bases: BaseModel
Discord guild/server model with metadata and relationships.
Represents a Discord guild (server) with associated metadata and relationships to other entities like snippets, cases, reminders, etc.
Attributes:
-
id(int) –Discord guild ID (primary key).
-
guild_joined_at((datetime, optional)) –When the bot joined this guild.
-
case_count(int) –Running count of moderation cases for this guild.
Methods:
-
__repr__–Return string representation showing guild ID.
-
serialize_datetimes–Serialize datetime objects to ISO format strings.
-
model_post_init–Ensure timestamp fields are always present in dict for compatibility.
-
to_dict–Convert model instance to dictionary with relationship support.
Functions¶
serialize_datetimes ¶
model_post_init ¶
model_post_init(__context: Any) -> None
Ensure timestamp fields are always present in dict for compatibility.
Even though timestamps are database-managed, some SQLAlchemy operations expect these fields to be accessible in the model's dict. This ensures compatibility without interfering with database defaults.
to_dict ¶
to_dict(
include_relationships: bool = False, relationships: list[str] | None = None
) -> dict[str, Any]
Convert model instance to dictionary with relationship support.
Parameters:
-
include_relationships(bool, default:False) –Whether to include relationship fields, by default False.
-
relationships(list[str] | None, default:None) –Specific relationships to include (if None, includes all), by default None.
Returns:
GuildConfig ¶
Bases: BaseModel
Guild-specific configuration settings.
Stores configuration options and settings for each Discord guild, controlling bot behavior and feature availability.
Attributes:
-
id(int) –Discord guild ID (primary key, foreign key to guild table).
-
prefix(str) –Command prefix for this guild.
-
mod_log_id((int, optional)) –Channel ID for moderation logs.
-
audit_log_id((int, optional)) –Channel ID for audit logs.
-
join_log_id((int, optional)) –Channel ID for member join/leave logs.
-
private_log_id((int, optional)) –Channel ID for private moderation logs.
-
report_log_id((int, optional)) –Channel ID for user reports.
-
dev_log_id((int, optional)) –Channel ID for development/debug logs.
-
jail_channel_id((int, optional)) –Channel ID for jailed users.
-
jail_role_id((int, optional)) –Role ID assigned to jailed users.
-
onboarding_completed(bool) –Whether guild onboarding setup is complete.
-
onboarding_stage((OnboardingStage, optional)) –Current stage of guild onboarding process.
-
controllers Classes-
GuildConfigController Functions-
delete_guild_prefix -
find_configs_by_field -
get_all_configs -
get_config_by_guild_id -
get_configs_by_prefix -
get_or_create_config -
mark_onboarding_completed -
reset_onboarding -
update_audit_log_id -
update_channel_field -
update_config -
update_config_field -
update_dev_log_id -
update_general_channel_id -
update_guild_prefix -
update_jail_channel_id -
update_join_log_id -
update_mod_log_id -
update_onboarding_stage -
update_perm_level_role -
update_private_log_id -
update_report_log_id -
update_starboard_channel_id
-
-
GuildController Functions
-
-
guild ClassesGuildController Functions -
guild_config ClassesGuildConfigController Functions-
delete_guild_prefix -
find_configs_by_field -
get_all_configs -
get_config_by_guild_id -
get_configs_by_prefix -
get_or_create_config -
mark_onboarding_completed -
reset_onboarding -
update_audit_log_id -
update_channel_field -
update_config -
update_config_field -
update_dev_log_id -
update_general_channel_id -
update_guild_prefix -
update_jail_channel_id -
update_join_log_id -
update_mod_log_id -
update_onboarding_stage -
update_perm_level_role -
update_private_log_id -
update_report_log_id -
update_starboard_channel_id
-
Methods:
-
__repr__–Return string representation showing guild ID and prefix.
-
serialize_datetimes–Serialize datetime objects to ISO format strings.
-
model_post_init–Ensure timestamp fields are always present in dict for compatibility.
-
to_dict–Convert model instance to dictionary with relationship support.
Functions¶
serialize_datetimes ¶
model_post_init ¶
model_post_init(__context: Any) -> None
Ensure timestamp fields are always present in dict for compatibility.
Even though timestamps are database-managed, some SQLAlchemy operations expect these fields to be accessible in the model's dict. This ensures compatibility without interfering with database defaults.
to_dict ¶
to_dict(
include_relationships: bool = False, relationships: list[str] | None = None
) -> dict[str, Any]
Convert model instance to dictionary with relationship support.
Parameters:
-
include_relationships(bool, default:False) –Whether to include relationship fields, by default False.
-
relationships(list[str] | None, default:None) –Specific relationships to include (if None, includes all), by default None.
Returns:
Levels ¶
Bases: SQLModel
User experience and leveling data.
Tracks user experience points and level progression within guilds.
Attributes:
-
member_id(int) –Discord user ID (primary key).
-
guild_id(int) –Guild ID (primary key, foreign key to guild table).
-
xp(float) –Experience points accumulated by the user.
-
level(int) –Current level derived from XP.
-
blacklisted(bool) –Whether user is blacklisted from gaining XP.
-
last_message(datetime) –Timestamp of last message for XP cooldown.
Methods:
-
__repr__–Return string representation showing member, guild, level and XP.
PermissionAssignment ¶
Bases: BaseModel
Assigns permission ranks to Discord roles in each server.
Maps Discord roles to permission ranks, granting all members with that role the associated permission level.
Attributes:
-
id((int, optional)) –Auto-generated primary key.
-
guild_id(int) –Guild ID where this assignment exists.
-
permission_rank_id(int) –ID of the permission rank being assigned.
-
role_id(int) –Discord role ID receiving the permission rank.
Methods:
-
__repr__–Return string representation showing guild, role and rank assignment.
-
serialize_datetimes–Serialize datetime objects to ISO format strings.
-
model_post_init–Ensure timestamp fields are always present in dict for compatibility.
-
to_dict–Convert model instance to dictionary with relationship support.
Functions¶
__repr__ ¶
__repr__() -> str
Return string representation showing guild, role and rank assignment.
serialize_datetimes ¶
model_post_init ¶
model_post_init(__context: Any) -> None
Ensure timestamp fields are always present in dict for compatibility.
Even though timestamps are database-managed, some SQLAlchemy operations expect these fields to be accessible in the model's dict. This ensures compatibility without interfering with database defaults.
to_dict ¶
to_dict(
include_relationships: bool = False, relationships: list[str] | None = None
) -> dict[str, Any]
Convert model instance to dictionary with relationship support.
Parameters:
-
include_relationships(bool, default:False) –Whether to include relationship fields, by default False.
-
relationships(list[str] | None, default:None) –Specific relationships to include (if None, includes all), by default None.
Returns:
PermissionCommand ¶
Bases: BaseModel
Assigns permission requirements to specific commands.
Allows guilds to customize the permission rank required for specific commands, overriding default permission requirements.
Attributes:
-
id((int, optional)) –Auto-generated primary key.
-
guild_id(int) –Guild ID where this command permission is set.
-
command_name(str) –Name of the command.
-
required_rank(int) –Minimum permission rank required (0-10).
-
description((str, optional)) –Optional description of the command.
Methods:
-
__repr__–Return string representation showing guild, command and rank requirement.
-
serialize_datetimes–Serialize datetime objects to ISO format strings.
-
model_post_init–Ensure timestamp fields are always present in dict for compatibility.
-
to_dict–Convert model instance to dictionary with relationship support.
Functions¶
__repr__ ¶
__repr__() -> str
Return string representation showing guild, command and rank requirement.
serialize_datetimes ¶
model_post_init ¶
model_post_init(__context: Any) -> None
Ensure timestamp fields are always present in dict for compatibility.
Even though timestamps are database-managed, some SQLAlchemy operations expect these fields to be accessible in the model's dict. This ensures compatibility without interfering with database defaults.
to_dict ¶
to_dict(
include_relationships: bool = False, relationships: list[str] | None = None
) -> dict[str, Any]
Convert model instance to dictionary with relationship support.
Parameters:
-
include_relationships(bool, default:False) –Whether to include relationship fields, by default False.
-
relationships(list[str] | None, default:None) –Specific relationships to include (if None, includes all), by default None.
Returns:
PermissionRank ¶
Bases: BaseModel
Permission ranks for guild role-based access control.
Defines hierarchical permission ranks that can be assigned to roles within a guild, controlling access to bot commands and features.
Attributes:
-
id((int, optional)) –Auto-generated primary key.
-
guild_id(int) –Guild ID this permission rank belongs to.
-
rank(int) –Numeric permission rank (0-100, higher = more permissions).
-
name(str) –Human-readable name for the permission rank.
-
description((str, optional)) –Optional description of the rank's purpose and permissions.
Methods:
-
__repr__–Return string representation showing guild, rank and name.
-
serialize_datetimes–Serialize datetime objects to ISO format strings.
-
model_post_init–Ensure timestamp fields are always present in dict for compatibility.
-
to_dict–Convert model instance to dictionary with relationship support.
Functions¶
serialize_datetimes ¶
model_post_init ¶
model_post_init(__context: Any) -> None
Ensure timestamp fields are always present in dict for compatibility.
Even though timestamps are database-managed, some SQLAlchemy operations expect these fields to be accessible in the model's dict. This ensures compatibility without interfering with database defaults.
to_dict ¶
to_dict(
include_relationships: bool = False, relationships: list[str] | None = None
) -> dict[str, Any]
Convert model instance to dictionary with relationship support.
Parameters:
-
include_relationships(bool, default:False) –Whether to include relationship fields, by default False.
-
relationships(list[str] | None, default:None) –Specific relationships to include (if None, includes all), by default None.
Returns:
Reminder ¶
Bases: SQLModel
Scheduled reminders for users.
Represents reminders that users can set to be notified about at a specific time.
Attributes:
-
id((int, optional)) –Auto-generated primary key.
-
reminder_content(str) –Content of the reminder message.
-
reminder_expires_at(datetime) –When the reminder should trigger.
-
reminder_channel_id(int) –Channel ID where reminder should be sent.
-
reminder_user_id(int) –Discord user ID who set the reminder.
-
reminder_sent(bool) –Whether the reminder has been sent.
-
guild_id(int) –Guild ID where the reminder was set.
Methods:
-
__repr__–Return string representation showing guild, user and expiration.
Snippet ¶
Bases: SQLModel
Custom command snippets for guilds.
Represents user-defined text snippets that can be triggered by custom commands within a Discord guild.
Attributes:
-
id((int, optional)) –Auto-generated primary key.
-
snippet_name(str) –Name of the snippet command.
-
snippet_content((str, optional)) –Content/text of the snippet.
-
snippet_user_id(int) –Discord user ID who created the snippet.
-
guild_id(int) –ID of the guild this snippet belongs to.
-
uses(int) –Number of times this snippet has been used.
-
locked(bool) –Whether the snippet is locked (prevents editing/deletion).
-
alias((str, optional)) –Optional alias name for the snippet.
-
controllers ClassesSnippetController Functions-
create_snippet -
create_snippet_alias -
find_many -
get_all_aliases -
get_all_snippets_by_guild_id -
get_popular_snippets -
get_snippet_by_id -
get_snippet_by_name_and_guild -
get_snippet_by_name_and_guild_id -
get_snippets_by_alias -
get_snippets_by_creator -
get_snippets_by_guild -
increment_snippet_uses -
search_snippets -
toggle_snippet_lock -
toggle_snippet_lock_by_id -
update_snippet -
update_snippet_by_id
-
-
create_snippet ClassesCreateSnippet Functions_get_snippet_or_error -
delete_snippet ClassesDeleteSnippet Functions_get_snippet_or_error -
edit_snippet ClassesEditSnippet Functions_get_snippet_or_error -
get_snippet ClassesSnippet Functions_get_snippet_or_error -
get_snippet_info ClassesSnippetInfo Functions_get_snippet_or_error -
list_snippets ClassesListSnippets Functions_get_snippet_or_error -
snippet ClassesSnippetController Functions-
create_snippet -
create_snippet_alias -
find_many -
get_all_aliases -
get_all_snippets_by_guild_id -
get_popular_snippets -
get_snippet_by_id -
get_snippet_by_name_and_guild -
get_snippet_by_name_and_guild_id -
get_snippets_by_alias -
get_snippets_by_creator -
get_snippets_by_guild -
increment_snippet_uses -
search_snippets -
toggle_snippet_lock -
toggle_snippet_lock_by_id -
update_snippet -
update_snippet_by_id
-
-
snippets ClassesSnippetsBaseCog Functions_get_snippet_or_error -
toggle_snippet_lock ClassesToggleSnippetLock Functions_get_snippet_or_error
-
create_snippet ClassesCreateSnippet Functions_create_snippets_list_embed -
delete_snippet ClassesDeleteSnippet Functions_create_snippets_list_embed -
edit_snippet ClassesEditSnippet Functions_create_snippets_list_embed -
get_snippet ClassesSnippet Functions_create_snippets_list_embed -
get_snippet_info ClassesSnippetInfo Functions_create_snippets_list_embed -
list_snippets ClassesListSnippets Functions_create_snippets_list_embed -
snippets ClassesSnippetsBaseCog Functions_create_snippets_list_embed -
toggle_snippet_lock ClassesToggleSnippetLock Functions_create_snippets_list_embed
Methods:
-
__repr__–Return string representation showing ID and name.
Starboard ¶
Bases: SQLModel
Starboard configuration for guilds.
Defines the starboard channel and emoji settings for a guild, allowing messages to be highlighted when they receive enough reactions.
Attributes:
-
id(int) –Guild ID (primary key, foreign key to guild table).
-
starboard_channel_id(int) –Discord channel ID where starred messages are posted.
-
starboard_emoji(str) –Emoji used for starring messages.
-
starboard_threshold(int) –Number of reactions needed to appear on starboard.
Methods:
-
__repr__–Return string representation showing guild and channel.
StarboardMessage ¶
Bases: SQLModel
Messages that have been starred on the starboard.
Tracks individual messages that have been posted to the starboard along with their star counts and original message information.
Attributes:
-
id(int) –Original Discord message ID (primary key).
-
message_content(str) –Content of the original message.
-
message_expires_at(datetime) –When the starboard entry expires.
-
message_channel_id(int) –Original channel ID where message was posted.
-
message_user_id(int) –Discord user ID of the message author.
-
message_guild_id(int) –Guild ID where the starboard is configured.
-
star_count(int) –Current number of star reactions.
-
starboard_message_id(int) –ID of the starboard message in the starboard channel.
Methods:
-
__repr__–Return string representation showing guild, original message and user.