# Command System ## Overview Echoion processes user commands from TeamSpeak chat messages. Commands are prefixed (default: `!`) and dispatched to appropriate handlers based on the command name. ## Command Architecture ```mermaid flowchart TB subgraph "Command Flow" User[User Message] --> Plugin[PluginInterface] Plugin --> Core[EchoionCore] Core --> CM[CommandManager] CM --> Parse[Parse Command] Parse --> Lookup[Lookup Handler] Lookup --> Check{Check
Permissions} Check -->|Denied| Deny[Permission Denied] Check -->|Allowed| Execute[Execute Handler] Execute --> Reply[Send Reply] Deny --> Reply end subgraph "Handler Registry" H1[play → PlayHandler] H2[pause → PauseHandler] H3[skip → SkipHandler] H4[volume → VolumeHandler] end Lookup --> H1 Lookup --> H2 Lookup --> H3 Lookup --> H4 ``` ## Command Processing Flow ```mermaid sequenceDiagram actor User participant TS as TeamSpeak participant PL as Plugin participant CO as Core participant CM as CommandManager User->>TS: Type "!play song name" TS->>PL: onTextMessageReceived PL->>CO: onPluginEvent CO->>CM: dispatch CM->>CM: Parse command CM->>CM: Extract arguments CM->>CM: Find handler CM->>CM: Check permissions alt Permission Granted CM->>CM: Execute handler CM->>CO: Process result CO->>PL: sendTextMessage PL->>TS: Display result TS->>User: See response else Permission Denied CM->>CO: Permission error CO->>PL: send error PL->>TS: Display error end ``` ## Command Categories ```mermaid flowchart TB subgraph "Command Categories" Music[Music Commands
Search & Play] Playback[Playback Commands
Control Audio] Queue[Queue Commands
Manage Queue] Utility[Utility Commands
Help & Info] Admin[Admin Commands
System Control] end Music --> Play[play, search] Playback --> Ctrl[pause, resume, skip, volume] Queue --> Q[queue, clear, shuffle, remove] Utility --> Util[help, nowplaying, subscribe] Admin --> Adm[reload, reloadconfig] ``` ### Category Permissions | Category | Description | Who Can Use | |----------|-------------|-------------| | **Music** | Search and play songs | All users | | **Playback** | Control playback | All users | | **Queue** | Queue management | Admin, DJ | | **Utility** | General utilities | All users | | **Admin** | System operations | Admin only | ## Available Commands ### Music Commands ```mermaid flowchart LR subgraph "Music" Play["!play
Play or queue song"] Search["!search
Search YouTube"] Select["!select
Pick from search"] end UserInput["User types..."] --> Play UserInput --> Search Search --> Results["Show results
[1] Song A
[2] Song B"] Results --> Select ``` | Command | Aliases | Description | Permission | |---------|---------|-------------|------------| | `play ` | `p` | Play song or add to queue | User | | `search ` | - | Search YouTube for tracks | User | | `select ` | - | Select track from search | User | ### Playback Commands ```mermaid flowchart LR subgraph "Playback Controls" Pause["!pause
Pause playback"] Resume["!resume
Continue playing"] Stop["!stop
Stop & clear"] Skip["!skip [n]
Skip track(s)"] Seek["!seek
Jump to position"] Vol["!volume <0-100>
Set volume"] end ``` | Command | Aliases | Description | Permission | |---------|---------|-------------|------------| | `pause` | - | Pause current playback | User | | `resume` | `unpause`, `continue` | Resume paused playback | User | | `stop` | - | Stop and clear current | User | | `skip [count]` | `next`, `s` | Skip to next track | User | | `seek ` | `jump` | Seek to position (MM:SS) | User | | `volume <0-100>` | `vol`, `v` | Set playback volume | User | ### Queue Commands ```mermaid flowchart TB subgraph "Queue Management" Show["!queue
Show queue"] Clear["!clear
Clear all"] Shuffle["!shuffle
Toggle shuffle"] Repeat["!repeat
Toggle repeat"] Remove["!remove
Remove track"] Move["!move
Reorder"] end ``` | Command | Aliases | Description | Permission | |---------|---------|-------------|------------| | `queue` | `q`, `list` | Display current queue | User | | `clear` | `empty` | Remove all tracks | Admin, DJ | | `shuffle` | `random` | Toggle shuffle mode | Admin, DJ | | `repeat` | `loop` | Toggle repeat mode | Admin, DJ | | `remove ` | `rm`, `delete` | Remove specific track | Admin, DJ | | `move ` | - | Reorder tracks | Admin, DJ | ### Utility Commands | Command | Aliases | Description | Permission | |---------|---------|-------------|------------| | `help [command]` | - | Show help information | User | | `nowplaying` | `np`, `current` | Show current track | User | | `subscribe` | `sub`, `join` | Subscribe to audio | User | | `unsubscribe` | `unsub`, `leave` | Unsubscribe from audio | User | ### Admin Commands ```mermaid flowchart LR subgraph "Admin Only" Reload["!reload
Hot reload core"] Config["!reloadconfig
Reload config"] end style Admin fill:#f96,stroke:#333 ``` | Command | Aliases | Description | Permission | |---------|---------|-------------|------------| | `reload` | `reloadcore` | Hot reload Core library | Admin | | `reloadconfig` | - | Reload configuration | Admin | ## Command Dispatch Flow ```mermaid flowchart TB Input["Input: !play song name"] --> Prefix{Starts with
prefix?} Prefix -->|No| Ignore[Ignore] Prefix -->|Yes| Extract Extract["Extract: command='play'
args='song name'"] --> Find{Handler
found?} Find -->|No| Unknown["Reply: Unknown command"] Find -->|Yes| Perm{Check
permission} Perm -->|Denied| NoPerm["Reply: No permission"] Perm -->|Allowed| Context["Create Context
clientId, args, reply"] Context --> Execute["Execute Handler"] Execute --> Result{Result} Result -->|Success| SuccessReply["Reply: Success message"] Result -->|Error| ErrorReply["Reply: Error message"] ``` ## Permission Check Flow ```mermaid flowchart TB Request[Command Request] --> Banned{Is Banned?} Banned -->|Yes| Deny1[Deny Access] Banned -->|No| AdminCmd{Admin
Command?} AdminCmd -->|Yes| IsAdmin{Is Admin?} IsAdmin -->|No| Deny2[Deny Access] IsAdmin -->|Yes| Allow1[Allow] AdminCmd -->|No| QueueCmd{Queue
Command?} QueueCmd -->|Yes| IsDJ{Is Admin/DJ?} IsDJ -->|No| Deny3[Deny Access] IsDJ -->|Yes| Allow2[Allow] QueueCmd -->|No| Allow3[Allow
Basic User] ``` ## Error Handling ```mermaid flowchart TB Error{Error Type} --> NotFound["Command Not Found
'Unknown command'"] Error --> NoPerm["Permission Denied
'No permission'"] Error --> BadArgs["Invalid Arguments
'Usage: !play '"] Error --> NotAvail["Not Available
'Music manager offline'"] NotFound --> Reply NoPerm --> Reply BadArgs --> Reply NotAvail --> Reply Reply[Send Reply to User] ``` ## Adding New Commands ```mermaid flowchart LR subgraph "Adding a Command" Create[Create Handler Class] Impl[Implement execute] Meta[Define Metadata] Reg[Register in Manager] end Create --> Impl Impl --> Meta Meta --> Reg Reg --> Test[Test] ``` ### Command Structure ```mermaid classDiagram class Command { <> +execute(context) +getDescription() +getUsage() +getCategory() +getAliases() +requiresAdmin() } class PlayCommand { +execute() +getDescription() "Play a song" +getCategory() Music +getAliases() [p] } class PauseCommand { +execute() +getDescription() "Pause playback" +getCategory() Playback } Command <|-- PlayCommand Command <|-- PauseCommand ``` ## Reply Formatting ```mermaid flowchart TB subgraph "Reply Types" Text["Plain Text
'Track added'"] Rich["Rich Format
'[b]Now Playing[/b]'"] Error["Error Message
'[color=red]Error[/color]'"] Multi["Multi-line
Track info"] end Text --> TS[TeamSpeak Display] Rich --> TS Error --> TS Multi --> TS ``` ## Command Aliases ```mermaid flowchart LR subgraph "Alias Resolution" A1["!p"] --> Play["!play"] A2["!q"] --> Queue["!queue"] A3["!np"] --> Now["!nowplaying"] A4["!vol"] --> Volume["!volume"] end Play --> Handler[Same Handler] Queue --> Handler Now --> Handler Volume --> Handler ```