feat(command): add ticket system
Description
This pull request introduces a support ticket system to Tux, including database schema changes, backend controllers, and Discord bot cogs with logging and configuration. The main changes add models and logic to manage tickets, track their status, and log transcripts with event metadata. Additionally, the database controller system is extended to support ticket operations.
Ticket System Implementation
- Prisma Schema
- Added a new
Ticketmodel andTicketStatusenum, including fields for ticket metadata and relations toGuildfor efficient querying. - Updated the
Guildmodel` to include a relation to tickets, enabling guild-level ticket management.
- Added a new
Database Controller Enhancements
- Implemented
TicketControllerwith methods for creating, updating (claim, unclaim, close), querying, and deleting tickets, following best practices for error handling and async operations. - Integrated
TicketControllerinto the mainDatabaseController, allowing unified access to ticket operations alongside existing controllers. - Registered the
Ticketmodel in base controller imports and type lists for proper ORM integration (base.py).
Discord Bot Ticket Logging & Configuration
- Added a new cog
TicketLogfor enhanced ticket transcript logging, including event tracking (claims, closes, permission changes), message analysis, and metadata-rich transcript files sent to a configurable log channel. - Added a configuration cog
TicketLogConfigto set and persist the ticket log channel per guild, supporting administrator-only slash commands for setup.
Minor Moderation Command Update
- Removed the
"t"alias from thetimeoutcommand to avoid conflicts or confusion.
Guidelines
-
My code follows the style guidelines of this project (formatted with Ruff)
-
I have performed a self-review of my own code
-
I have commented my code, particularly in hard-to-understand areas
-
I have made corresponding changes to the documentation if needed
-
My changes generate no new warnings
-
I have tested this change
-
Any dependent changes have been merged and published in downstream modules
-
I have added all appropriate labels to this PR
-
[x] I have followed all of these guidelines.
How Has This Been Tested? (if applicable)
I ran Tux in dev mode and tested it with mods from ATL in a private server.
Screenshots (if applicable)
Please add screenshots to help explain your changes.
Additional Information
Please add any other information that is important to this PR.
Summary by Sourcery
Add a comprehensive support ticket system to the bot, encompassing database schema updates, a new TicketController, Discord commands and cogs for ticket creation and management, interactive UI views, and a transcript logging subsystem with configurable log channel per guild
New Features:
- Add full support ticket system with commands for creating, claiming, unclaiming, closing, listing, and managing tickets
- Introduce TicketController with create, claim, unclaim, close, query, and delete operations integrated into the DatabaseController
- Define Ticket model and TicketStatus enum in Prisma schema and link tickets to Guild and GuildConfig
- Provide TicketLog cog for transcript logging with event tracking and metadata-rich logs
- Provide TicketLogConfig cog to configure the ticket log channel per guild
- Add interactive UI views (RequestCloseView and TicketManagementView) for ticket workflows
Enhancements:
- Extend base controller imports and DatabaseController to include ticket operations
- Remove conflicting alias from timeout command
Reviewer's Guide
Implements a full support ticket system by extending the Prisma schema, adding a dedicated TicketController integrated into the database layer, and introducing Discord cogs (Tickets, TicketLog, TicketLogConfig) along with UI views for lifecycle management and transcript logging, plus a minor alias update.
Sequence diagram for ticket creation and channel setup
sequenceDiagram
actor User
participant DiscordBot
participant TicketsCog
participant TicketController
participant Guild
User->>DiscordBot: /ticket create [title]
DiscordBot->>TicketsCog: handle create command
TicketsCog->>TicketController: create_ticket(guild_id, 0, author_id, title)
TicketController-->>TicketsCog: Ticket object
TicketsCog->>Guild: create_category(name)
TicketsCog->>Guild: create_text_channel(name, overwrites, category)
TicketsCog->>TicketController: update(ticket_id, channel_id)
TicketsCog->>DiscordBot: send ticket intro message
DiscordBot-->>User: Ticket created confirmation
Sequence diagram for ticket claim and unclaim actions
sequenceDiagram
actor Staff
participant DiscordBot
participant TicketManagementView
participant TicketController
participant Guild
Staff->>DiscordBot: Claim Ticket (button)
DiscordBot->>TicketManagementView: claim_ticket()
TicketManagementView->>TicketController: claim_ticket(channel_id, staff_id)
TicketController-->>TicketManagementView: updated Ticket
TicketManagementView->>Guild: set_permissions (restrict access)
TicketManagementView->>DiscordBot: update ticket message
Staff->>DiscordBot: Unclaim Ticket (button)
DiscordBot->>TicketManagementView: unclaim_ticket()
TicketManagementView->>TicketController: unclaim_ticket(channel_id)
TicketController-->>TicketManagementView: updated Ticket
TicketManagementView->>Guild: restore staff permissions
TicketManagementView->>DiscordBot: update ticket message
Class diagram for TicketController and integration with DatabaseController
classDiagram
class DatabaseController {
+TicketController ticket
...
}
class TicketController {
+create_ticket(guild_id, channel_id, author_id, title)
+claim_ticket(channel_id, moderator_id)
+unclaim_ticket(channel_id)
+close_ticket(channel_id)
+get_ticket_by_channel(channel_id)
+get_guild_tickets(guild_id, status, limit)
+get_user_tickets(guild_id, user_id, status)
+delete_ticket(channel_id)
}
DatabaseController --> TicketController
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Extended Prisma schema to support tickets and guild relations |
|
prisma/schema/commands/moderation.prismaprisma/schema/guild/guild.prisma |
| Created and integrated TicketController into database layer |
|
tux/database/controllers/ticket.pytux/database/controllers/__init__.pytux/database/controllers/base.py |
| Enhanced GuildConfigController for ticket log channel management |
|
tux/database/controllers/guild_config.py |
| Added Tickets cog for ticket lifecycle commands |
|
tux/cogs/moderation/tickets.py |
| Implemented TicketLog cog for transcript logging with event tracking |
|
tux/cogs/utility/ticket_log.py |
| Added TicketLogConfig cog for log channel configuration |
|
tux/cogs/utility/ticket_log_config.py |
| Introduced UI views for ticket interactions |
|
tux/ui/views/tickets.py |
| Minor modification to existing moderation command |
|
tux/cogs/moderation/timeout.py |
Possibly linked issues
- #1: The PR implements the core functionalities of the base ticketing system, like creating, closing, and managing users.
- #0: The PR implements the 'Ticket System' feature explicitly listed in the roadmap issue for v0.8.0.
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
@sourcery-ai review
@sourcery-ai resolve