tux icon indicating copy to clipboard operation
tux copied to clipboard

feat(command): add ticket system

Open nomnomshark41 opened this issue 4 months ago • 3 comments

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 Ticket model and TicketStatus enum, including fields for ticket metadata and relations to Guild for efficient querying.
    • Updated the Guild model` to include a relation to tickets, enabling guild-level ticket management.

Database Controller Enhancements

  • Implemented TicketController with methods for creating, updating (claim, unclaim, close), querying, and deleting tickets, following best practices for error handling and async operations.
  • Integrated TicketController into the main DatabaseController, allowing unified access to ticket operations alongside existing controllers.
  • Registered the Ticket model in base controller imports and type lists for proper ORM integration (base.py).

Discord Bot Ticket Logging & Configuration

  • Added a new cog TicketLog for 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 TicketLogConfig to 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 the timeout command 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

nomnomshark41 avatar Aug 21 '25 14:08 nomnomshark41

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
  • Added Ticket model and TicketStatus enum
  • Linked tickets to Guild model
  • Prepared config schema for ticket log field
prisma/schema/commands/moderation.prisma
prisma/schema/guild/guild.prisma
Created and integrated TicketController into database layer
  • Implemented CRUD methods (create, claim, unclaim, close, query, delete)
  • Registered TicketController in DatabaseController and BaseController
  • Enabled unified access via getattr mapping
tux/database/controllers/ticket.py
tux/database/controllers/__init__.py
tux/database/controllers/base.py
Enhanced GuildConfigController for ticket log channel management
  • Extended get_log_channel lookup for ticket type
  • Added get_ticket_log_id and update_ticket_log_id methods
tux/database/controllers/guild_config.py
Added Tickets cog for ticket lifecycle commands
  • Implemented hybrid commands for create, claim, unclaim, close, list, stats, leaderboard
  • Handled channel creation, permission overwrites, cleanup scheduling
  • Integrated error handling, embed responses, and slash command support
tux/cogs/moderation/tickets.py
Implemented TicketLog cog for transcript logging with event tracking
  • Tracked ticket events outside messages
  • Generated combined transcript file with metadata and tags
  • Sent transcripts to configurable log channel with summary embed
tux/cogs/utility/ticket_log.py
Added TicketLogConfig cog for log channel configuration
  • Provided slash command to set ticket log channel per guild
  • Exposed method to retrieve stored channel ID
tux/cogs/utility/ticket_log_config.py
Introduced UI views for ticket interactions
  • Built RequestCloseView for author close confirmation
  • Built TicketManagementView with claim/unclaim buttons and dynamic state updates
tux/ui/views/tickets.py
Minor modification to existing moderation command
  • Removed conflicting "t" alias from timeout 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 review on 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 issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on 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 dismiss on 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 review to 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[bot] avatar Aug 21 '25 14:08 sourcery-ai[bot]

@sourcery-ai review

nomnomshark41 avatar Aug 24 '25 19:08 nomnomshark41

@sourcery-ai resolve

nomnomshark41 avatar Aug 24 '25 19:08 nomnomshark41