Skip to content

feat: add slash command equivalents for all commands#63

Open
davelindsay84 wants to merge 1 commit into
mainfrom
feat/slash-commands
Open

feat: add slash command equivalents for all commands#63
davelindsay84 wants to merge 1 commit into
mainfrom
feat/slash-commands

Conversation

@davelindsay84

Copy link
Copy Markdown
Collaborator

Summary

Implements every command as a Discord slash command alongside the existing !-prefixed commands, which continue to work unchanged. Passive scoring (phrase++, ✨phrase✨) is untouched.

Message command Slash equivalent
!s <search>/<replacement> /s search:<text> replacement:<text> (omit replacement to delete)
!score <phrase> /score phrase:<text>
!trending /trending
!leader <emoji> /leader emoji:<emoji>
!configDump /configdump (lowercase — Discord requires it)

Changes

  • commands.js (new) — slashCommands schema (SlashCommandBuilder) + handleInteraction dispatcher. Handlers reuse the same primitives as the message path (replaceFirstMessage, getScore, getTrending, getLeaderboard, registerProxyMessage, oneBlockedMessage).
  • deploy-commands.js (new) — registration script (npm run deploy). Guild-scoped when GUILD_ID is set (instant), else global. App ID is derived from the bot token — no extra env var.
  • index.jsinteractionCreate listener with error handling (ephemeral "something broke" fallback).
  • config.js — adds GuildId from GUILD_ID.
  • replacer.js — exports isBlockedPhrase so /s can gate blocked phrases directly.
  • __tests__/commands.test.js (new) — handler coverage for every command.
  • CLAUDE.md — documents slash commands, new modules, and GUILD_ID.

Behavior notes

  • /s defers (history fetch can exceed Discord's 3s window), routes the quote through interaction.editReply so the bot's reply is the quote, and registers the reaction-credit proxy exactly like !s.
  • Where the ! path stays silent (blocked phrases) the slash path must acknowledge, so it replies ephemerally ("nope"); a disabled /configdump likewise replies ephemerally.

Deploying

Set GUILD_ID in .env, run npm run deploy once, and ensure the bot was invited with the applications.commands OAuth scope.

Testing

  • npm test — 153 passing, coverage thresholds met
  • npm run lint — clean

🤖 Generated with Claude Code

Implement /s, /score, /trending, /leader, and /configdump as Discord slash
commands alongside the existing !-prefixed commands, which continue to work.

- commands.js: SlashCommandBuilder schema + handleInteraction dispatcher,
  reusing the same primitives as the message path
- deploy-commands.js: registration script (npm run deploy), guild-scoped via
  GUILD_ID or global; derives the app ID from the bot token
- index.js: interactionCreate listener with error handling
- config.js: add GuildId (GUILD_ID)
- replacer.js: export isBlockedPhrase for the /s blocked-phrase gate
- __tests__/commands.test.js: handler coverage for every command
- CLAUDE.md: document slash commands, modules, and GUILD_ID

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant