Skip to content

refactor: extract buildBrandedEmbed + logEntitlementEvent, migrate stragglers to withCommandLogging#22

Merged
nathanialhenniges merged 2 commits into
mainfrom
claude/reverent-curran-9ba47d
May 16, 2026
Merged

refactor: extract buildBrandedEmbed + logEntitlementEvent, migrate stragglers to withCommandLogging#22
nathanialhenniges merged 2 commits into
mainfrom
claude/reverent-curran-9ba47d

Conversation

@nathanialhenniges
Copy link
Copy Markdown
Member

Summary

Follow-up duplication audit after #20 / 7801952 (refactor: extract duplicated patterns into shared helper utilities). Audited full src/ with the audit-duplicates skill; this PR fixes the remaining HIGH/MEDIUM findings.

What changed

New helpers

  • src/utils/embedHelpers.tsbuildBrandedEmbed, BRAND_COLOR (0xfadb7f), BRAND_FOOTER ("Powered by MrDemonWolf, Inc."). Single source of truth — previously duplicated across 9 callsites.
  • src/utils/entitlementHelpers.ts — added logEntitlementEvent(eventName, message, entitlement, extras?). Used by all three entitlement event handlers.

Migrated to withCommandLogging (7 holdouts that still hand-rolled try/catch + logger.commands.executing/error + safeErrorReply)

  • src/commands/help.ts, about.ts, invite.ts, changelog.ts
  • src/commands/admin/quote/create.ts, admin/quote/remove.ts
  • src/commands/admin/activity/create.ts, admin/activity/remove.ts
  • src/commands/admin/suggestion/stats.ts
  • src/commands/setup/channel.ts — also fixes pre-existing bug where success/error were logged under command name "setup" instead of "setup channel".

Embed callers refactored to buildBrandedEmbed

  • src/commands/premium.ts, setup/schedule.ts, admin/quote/create.ts, admin/suggestion/stats.ts, changelog.ts, about.ts
  • src/utils/quoteHelpers.ts (buildMotivationEmbed)
  • src/utils/premium.ts (buildPremiumUpsell)

Entitlement events

  • src/events/entitlementCreate.ts, entitlementDelete.ts, entitlementUpdate.ts — all now use logEntitlementEvent for the shared payload shape.

Why

Stats

19 files changed, 194 insertions(+), 435 deletions(-) — net -241 LOC.

Test plan

  • bun run typecheck clean
  • bun run lint:check clean
  • bun test — 244 pass, 0 fail
  • Manual: run /help, /about, /invite, /changelog, /premium, /setup channel, /setup schedule, /admin quote create|remove, /admin activity create|remove, /admin suggestion stats — verify embeds render and error path replies ephemerally.
  • Manual: trigger entitlement create/delete/update — verify log payloads contain userId/skuId/guildId/timestamp.

Notes for reviewer

  • LOW finding fetchRecordOrReply<T> (admin quote/activity remove) intentionally skipped — only 2 callsites, abstraction not worth the Drizzle-generic complexity yet.
  • Post-validation in admin create/remove (if (!val.trim())) kept — existing tests assert it.
  • env.ts vs envSchema.ts split confirmed intentional (test import boundary).

🤖 Generated with Claude Code

…ragglers to withCommandLogging

Follow-up duplication audit after #20. Consolidates remaining copy-paste:

- New src/utils/embedHelpers.ts with buildBrandedEmbed, BRAND_COLOR, BRAND_FOOTER.
  Single source of truth for brand color (0xfadb7f) and footer; previously
  duplicated across 9 callsites.
- New logEntitlementEvent in src/utils/entitlementHelpers.ts. Entitlement
  Create/Delete/Update events now share one logging shape.
- Migrated 7 commands from hand-rolled try/catch + executing/error logging
  to withCommandLogging: help, about, invite, changelog, admin/quote/create,
  admin/quote/remove, admin/activity/create, admin/activity/remove,
  admin/suggestion/stats, setup/channel. Fixes setup/channel logging the wrong
  command name on success/error.
- Refactored premium-cmd, setup/schedule, quoteHelpers.buildMotivationEmbed,
  premium.buildPremiumUpsell, admin/suggestion/stats, changelog, about,
  admin/quote/create embed scaffolding through buildBrandedEmbed.

Tests: 244 pass, 0 fail. typecheck + lint clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

@nathanialhenniges has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 27 minutes and 50 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fe2c41d6-70e8-45c7-851a-afd76ecaa3c0

📥 Commits

Reviewing files that changed from the base of the PR and between 8ef1f21 and d9a00e7.

📒 Files selected for processing (25)
  • src/commands/about.ts
  • src/commands/admin/activity/create.ts
  • src/commands/admin/activity/remove.ts
  • src/commands/admin/quote/create.ts
  • src/commands/admin/quote/remove.ts
  • src/commands/admin/suggestion/stats.ts
  • src/commands/changelog.ts
  • src/commands/help.ts
  • src/commands/invite.ts
  • src/commands/premium.ts
  • src/commands/quote.ts
  • src/commands/quoteDeps.ts
  • src/commands/setup/channel.ts
  • src/commands/setup/schedule.ts
  • src/events/entitlementCreate.ts
  • src/events/entitlementDelete.ts
  • src/events/entitlementUpdate.ts
  • src/utils/embedHelpers.ts
  • src/utils/entitlementHelpers.ts
  • src/utils/premium.ts
  • src/utils/quoteHelpers.ts
  • src/worker/jobs/sendMotivation.ts
  • src/worker/jobs/sendMotivationDeps.ts
  • tests/commands/quote.test.ts
  • tests/worker/sendMotivation.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/reverent-curran-9ba47d

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

CI surfaced 3 quoteHelpers test failures: the bun:test mock.module
registry is process-global, so tests/commands/quote.test.ts and
tests/worker/sendMotivation.test.ts mocking src/utils/quoteHelpers.js
poisoned tests/utils/quoteHelpers.test.ts whenever bun's test discovery
walked those files first. Same root cause #21 fought with readyDeps /
commandRegistry shims.

Apply the same shim pattern:

- New src/commands/quoteDeps.ts re-exports buildMotivationEmbed,
  getRandomMotivationQuote, resolveQuoteAuthor. src/commands/quote.ts
  imports from the shim. quote.test.ts mocks the shim, not the real
  module.
- New src/worker/jobs/sendMotivationDeps.ts mirrors the same shim for
  the worker job. sendMotivation.test.ts mocks the shim.

Local: 244 pass, 0 fail. typecheck clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@nathanialhenniges nathanialhenniges merged commit 3fa76c1 into main May 16, 2026
5 checks passed
@nathanialhenniges nathanialhenniges deleted the claude/reverent-curran-9ba47d branch May 16, 2026 12:10
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