|
| 1 | +# WARP.md |
| 2 | + |
| 3 | +This file provides guidance to WARP (warp.dev) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +PhoenixBot is a Discord bot built with Java 21 using JDA (Java Discord API) for handling Discord interactions. The bot provides ticket management, voting systems, FAQ handling, and support for "The Broken Script" modpack community. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Build & Run |
| 12 | +- **Build**: `.\gradlew.bat build` (Windows) or `./gradlew build` (Unix) |
| 13 | +- **Run**: `.\gradlew.bat run` (Windows) or `./gradlew run` (Unix) |
| 14 | +- **Build Shadow JAR**: `.\gradlew.bat shadowJar` (Windows) or `./gradlew shadowJar` (Unix) |
| 15 | + |
| 16 | +### Testing |
| 17 | +- **Run all tests**: `.\gradlew.bat test` (Windows) or `./gradlew test` (Unix) |
| 18 | +- **Run specific test**: `.\gradlew.bat test --tests "TestClassName"` (Windows) or `./gradlew test --tests "TestClassName"` (Unix) |
| 19 | + |
| 20 | +### Development |
| 21 | +- **Clean build**: `.\gradlew.bat clean build` (Windows) or `./gradlew clean build` (Unix) |
| 22 | +- **Continuous build**: `.\gradlew.bat build --continuous` (Windows) or `./gradlew build --continuous` (Unix) |
| 23 | + |
| 24 | +## Architecture Overview |
| 25 | + |
| 26 | +### Core Components |
| 27 | + |
| 28 | +#### Configuration System |
| 29 | +- **Config.java**: Central configuration management using YAML (SnakeYAML) |
| 30 | +- **config.yml**: Auto-generated configuration file with Discord IDs and bot settings |
| 31 | +- Singleton pattern for configuration access with automatic default config creation |
| 32 | +- Supports hot-reloading via `/reloadconfig` command |
| 33 | + |
| 34 | +#### Storage Layer |
| 35 | +- **VoteStorage.java**: JSON-based persistent storage for suggestion voting data |
| 36 | +- **TicketStorage.java**: JSON-based storage for ticket management with global counters |
| 37 | +- Uses Jackson for JSON serialization/deserialization |
| 38 | +- Thread-safe synchronized operations for concurrent access |
| 39 | + |
| 40 | +#### Event-Driven Architecture |
| 41 | +The bot follows JDA's event-driven pattern with specialized listener classes: |
| 42 | + |
| 43 | +**Core Listeners:** |
| 44 | +- **Listener.java**: Main ready event handler, command registration, and bot initialization |
| 45 | +- **SupportListener.java**: Handles support forum thread creation and closing |
| 46 | +- **SuggestionListener.java**: Manages voting on suggestion forum posts |
| 47 | +- **BugReportListener.java**: Processes bug report submissions |
| 48 | +- **ThreadDeleteListener.java**: Cleanup when threads are deleted |
| 49 | + |
| 50 | +**Ticket System:** |
| 51 | +- **Panel.java**: Ticket panel creation, button interactions, and automated ticket lifecycle |
| 52 | +- **TicketCloseHandler.java**: Handles ticket closing confirmations and cleanup |
| 53 | +- **CloseHandler.java**: Generic close handling for forum posts |
| 54 | + |
| 55 | +#### Command System |
| 56 | +- **CommandRegistry.java**: Central slash command registration |
| 57 | +- Individual command classes (InfoCommand, FAQCommand, TBSCommand, CloseCommand) |
| 58 | +- Commands are registered as event listeners in the main Bot class |
| 59 | + |
| 60 | +### Data Flow |
| 61 | + |
| 62 | +1. **Bot Initialization**: Config loads → Storage initializes → Commands register → Event listeners attach |
| 63 | +2. **Ticket Creation**: User clicks panel button → Thread creates → Storage saves → Auto-delete schedules |
| 64 | +3. **Ticket Response**: User responds → Auto-delete cancels → Moderators ping → Storage updates |
| 65 | +4. **Vote Management**: User votes → Storage updates → Vote counts sync with Discord reactions |
| 66 | +5. **Configuration Changes**: `/reloadconfig` → Config reloads → All components refresh |
| 67 | + |
| 68 | +### Key Design Patterns |
| 69 | + |
| 70 | +#### Singleton Pattern |
| 71 | +- **Config**: Single instance with lazy initialization and reload capability |
| 72 | + |
| 73 | +#### Observer Pattern |
| 74 | +- JDA event listeners for Discord events (messages, interactions, thread events) |
| 75 | + |
| 76 | +#### Strategy Pattern |
| 77 | +- Different handlers for different forum types (support, suggestions, bug reports) |
| 78 | + |
| 79 | +#### Factory Pattern |
| 80 | +- Ticket name generation with global counters and username sanitization |
| 81 | + |
| 82 | +### Storage Architecture |
| 83 | + |
| 84 | +#### Persistent Storage |
| 85 | +- **votes.json**: Stores vote data per thread with user voting history |
| 86 | +- **tickets.json**: Stores ticket metadata, creation times, and response status |
| 87 | +- **config.yml**: Bot configuration with Discord channel/role IDs |
| 88 | + |
| 89 | +#### In-Memory Storage |
| 90 | +- **pendingTickets**: ConcurrentHashMap tracking scheduled ticket deletions |
| 91 | +- **scheduler**: ScheduledExecutorService for automated ticket cleanup |
| 92 | + |
| 93 | +### Integration Points |
| 94 | + |
| 95 | +#### Discord Integration |
| 96 | +- **JDA Library**: Main Discord API wrapper |
| 97 | +- **Slash Commands**: Modern Discord interaction system |
| 98 | +- **Forum Channels**: Specialized channel type handling for tickets/suggestions |
| 99 | +- **Thread Management**: Automatic thread creation and lifecycle management |
| 100 | + |
| 101 | +#### External Dependencies |
| 102 | +- **Jackson**: JSON processing for storage operations |
| 103 | +- **SnakeYAML**: YAML configuration parsing |
| 104 | +- **Logback**: Structured logging with custom Discord-friendly formatting |
| 105 | +- **Apache HttpClient**: HTTP operations for log uploading |
| 106 | + |
| 107 | +## Configuration Notes |
| 108 | + |
| 109 | +The bot expects a `config.yml` file in the root directory. If missing, it auto-generates a template. Key sections: |
| 110 | +- **bot**: Token, activity, owner ID, guild ID |
| 111 | +- **logging**: Log channel configuration |
| 112 | +- **voting/support/bugReport**: Forum channel IDs |
| 113 | +- **roles**: Moderator roles for permissions |
| 114 | +- **faq**: FAQ channel and entries configuration |
| 115 | +- **tickets**: Ping roles for ticket notifications |
| 116 | + |
| 117 | +## Development Guidelines |
| 118 | + |
| 119 | +### Adding New Commands |
| 120 | +1. Create command class extending ListenerAdapter |
| 121 | +2. Implement onSlashCommandInteraction method |
| 122 | +3. Add command to CommandRegistry.registerCommands() |
| 123 | +4. Register listener in Bot.main() event listeners list |
| 124 | + |
| 125 | +### Adding New Storage |
| 126 | +1. Create storage class following VoteStorage/TicketStorage patterns |
| 127 | +2. Use synchronized methods for thread safety |
| 128 | +3. Initialize in Bot.initStorage() method |
| 129 | +4. Add getter method to Bot class for global access |
| 130 | + |
| 131 | +### Forum Integration |
| 132 | +- Each forum type (support, suggestions, bugs) has dedicated listener |
| 133 | +- Thread creation triggers automatic embed and button setup |
| 134 | +- Use ThreadChannel.getId() for unique identification |
| 135 | +- Always check forum channel IDs against configuration |
| 136 | + |
| 137 | +### Error Handling |
| 138 | +- Use SLF4J logging with Bot.class logger reference |
| 139 | +- Handle IOException for all storage operations |
| 140 | +- Provide user-friendly error messages for Discord interactions |
| 141 | +- Log errors with context (thread ID, user ID, action attempted) |
0 commit comments