refactor: extract buildBrandedEmbed + logEntitlementEvent, migrate stragglers to withCommandLogging#22
Conversation
…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>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (25)
✨ 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 |
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>
Summary
Follow-up duplication audit after #20 / 7801952 (
refactor: extract duplicated patterns into shared helper utilities). Audited fullsrc/with theaudit-duplicatesskill; this PR fixes the remaining HIGH/MEDIUM findings.What changed
New helpers
src/utils/embedHelpers.ts—buildBrandedEmbed,BRAND_COLOR(0xfadb7f),BRAND_FOOTER("Powered by MrDemonWolf, Inc."). Single source of truth — previously duplicated across 9 callsites.src/utils/entitlementHelpers.ts— addedlogEntitlementEvent(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.tssrc/commands/admin/quote/create.ts,admin/quote/remove.tssrc/commands/admin/activity/create.ts,admin/activity/remove.tssrc/commands/admin/suggestion/stats.tssrc/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
buildBrandedEmbedsrc/commands/premium.ts,setup/schedule.ts,admin/quote/create.ts,admin/suggestion/stats.ts,changelog.ts,about.tssrc/utils/quoteHelpers.ts(buildMotivationEmbed)src/utils/premium.ts(buildPremiumUpsell)Entitlement events
src/events/entitlementCreate.ts,entitlementDelete.ts,entitlementUpdate.ts— all now uselogEntitlementEventfor the shared payload shape.Why
withCommandLoggingadopted unevenly post-refactor: extract duplicated patterns into shared helpers #20 ⇒ drift bug already present insetup/channel.ts(wrong command name in success log).Stats
19 files changed, 194 insertions(+), 435 deletions(-)— net -241 LOC.Test plan
bun run typecheckcleanbun run lint:checkcleanbun test— 244 pass, 0 fail/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.userId/skuId/guildId/timestamp.Notes for reviewer
fetchRecordOrReply<T>(admin quote/activity remove) intentionally skipped — only 2 callsites, abstraction not worth the Drizzle-generic complexity yet.if (!val.trim())) kept — existing tests assert it.env.tsvsenvSchema.tssplit confirmed intentional (test import boundary).🤖 Generated with Claude Code