feat: custom command aliases per guild (#166)#203
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds per-guild custom slash-command aliases so server admins can define shortcuts (e.g. /w → /warn) that show up in Discord’s command picker and route transparently to the target command at runtime.
Changes:
- Introduces
guild_command_aliasespersistence (migration) and an in-memory alias cache loaded at startup. - Adds a new
/aliasadmin command to add/remove/list aliases. - Updates the interaction handler to resolve aliases before permission checks and command execution; adds module + command tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
migrations/004_command_aliases.cjs |
Creates guild_command_aliases table and supporting index. |
src/modules/commandAliases.js |
Implements alias CRUD, Discord guild-command registration/deregistration, and cache loading/resolution. |
src/commands/alias.js |
Adds `/alias add |
src/index.js |
Loads aliases on startup; resolves aliases for slash-command execution. |
tests/modules/commandAliases.test.js |
Unit tests covering cache load/resolve/list and add/remove flows with mocked Discord REST + DB. |
tests/commands/alias.test.js |
Command-level tests for /alias subcommands and error handling paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
| Filename | Overview |
|---|---|
| src/modules/commandAliases.js | Core alias functionality with good error handling and rollback logic; ON CONFLICT clause may leave orphaned Discord commands if alias update is attempted |
| src/commands/alias.js | Well-implemented command with comprehensive validation, prevents shadowing built-in commands and circular alias references |
| src/index.js | Clean integration of alias resolution before permission checks, ensures permissions are evaluated against target command |
Sequence Diagram
sequenceDiagram
participant Admin
participant Discord
participant AliasCmd as /alias Command
participant Module as commandAliases Module
participant DB as PostgreSQL
participant Cache as In-Memory Cache
Note over Admin,Cache: Creating an Alias
Admin->>Discord: /alias add w warn
Discord->>AliasCmd: interaction
AliasCmd->>AliasCmd: Validate alias name
AliasCmd->>AliasCmd: Check no built-in conflict
AliasCmd->>Module: addAlias(w → warn)
Module->>Discord: POST guild command /w
Discord-->>Module: command ID
Module->>DB: INSERT with discord_command_id
DB-->>Module: success
Module->>Cache: Update cache
Module-->>AliasCmd: {alias: w, target: warn}
AliasCmd-->>Admin: ✅ Created alias
Note over Admin,Cache: Using an Alias
Admin->>Discord: /w @user reason
Discord->>AliasCmd: interaction (commandName: w)
AliasCmd->>Cache: resolveAlias(w)
Cache-->>AliasCmd: warn
AliasCmd->>AliasCmd: Check permissions for warn
AliasCmd->>AliasCmd: Execute warn command
AliasCmd-->>Admin: Warning issued
Last reviewed commit: e10cad3
Summary
Closes #166
Allows guild admins to create custom aliases for bot commands (e.g.
/w→/warn).How it works
guild_command_aliasesdatabase table, scoped per guild.Map<guildId, Map<alias, target>>, giving O(1) resolution on every interaction.interactionCreatehandler resolves the alias to its target command before permission checks and execution. Permissions are evaluated against the target command, not the alias name.Files changed
migrations/004_command_aliases.cjsguild_command_aliasestable withUNIQUE(guild_id, alias)src/modules/commandAliases.jsaddAlias,removeAlias,listAliases,resolveAlias,loadAliasesFromDbsrc/commands/alias.js/alias add,/alias remove,/alias listslash commandsrc/index.jsinteractionCreatetests/modules/commandAliases.test.jstests/commands/alias.test.jsUsage
Test results