Skip to content

refactor: extract duplicated code patterns into shared utilities#2

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1780360596-refactor-shared-utilities
Open

refactor: extract duplicated code patterns into shared utilities#2
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1780360596-refactor-shared-utilities

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 2, 2026

Copy link
Copy Markdown

Summary

Seven commands (ban, kick, mute, clear, slowmode, lock, Good) duplicated the same patterns: admin-role gate, member-fetch-or-reply, actionability check (bannable/kickable/moderatable), error-embed construction, and error-handler boilerplate. index.js and deploy-commands.js each had their own copy of the command-directory traversal loop.

This PR extracts those into three new shared modules:

Module Exports
utils/embedHelpers.js errorEmbed(title, desc), successEmbed(title, fields, opts), accessDeniedEmbed(), moderationSuccessEmbed(title, user, reason, moderator, extraFields)
utils/commandHelpers.js checkAdmin(interaction), fetchMemberOrReply(interaction, userId), checkActionable(interaction, member, perm, actionName), handleCommandError(interaction, client, cmdName, error)
utils/commandLoader.js forEachCommand(baseDir, logger, callback) — shared iteration over commands/*/ used by both index.js and deploy-commands.js

Net result: −479 / +426 lines (−53 net), with each command file reduced to its unique logic only. All 14 commands load and resolve successfully.

Also adds the missing package-lock.json to fix the preexisting CI cache failure.

Link to Devin session: https://app.devin.ai/sessions/f2499b3b48cd4b8daeae817303088d33
Requested by: @AliCloud0

- Add utils/embedHelpers.js: errorEmbed, successEmbed, accessDeniedEmbed, moderationSuccessEmbed
- Add utils/commandHelpers.js: checkAdmin, fetchMemberOrReply, checkActionable, handleCommandError
- Add utils/commandLoader.js: forEachCommand() shared by index.js and deploy-commands.js
- Refactor ban, kick, mute, clear, slowmode, lock, Good commands to use shared helpers
- Refactor index.js and deploy-commands.js to use commandLoader

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.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