Repository navigation
feat(bot): make presence rotation configurable - #483
LucasSantana-Dev wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 13 minutes and 16 seconds. ⌛ 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 (2)
📝 WalkthroughWalkthroughAdded an optional Changes
Sequence DiagramsequenceDiagram
participant Env as Environment
participant PresenceUtils as presenceStatus.ts
participant PresenceHandler as presence.ts
participant Discord as Discord Client
Env->>PresenceUtils: Read BOT_PRESENCE_ACTIVITIES
PresenceUtils->>PresenceUtils: Parse pipe-separated entries & map types
PresenceUtils->>PresenceUtils: Validate entries, extract template and optional fallback
PresenceUtils-->>PresenceHandler: Return PresenceActivityTemplate[]
PresenceHandler->>PresenceHandler: Rotate templates, compute metrics ({guildCount}, etc.)
PresenceHandler->>PresenceHandler: Render name (use fallback if activeMusicSessions == 0)
PresenceHandler->>PresenceHandler: Truncate to 128 chars
PresenceHandler->>Discord: setPresence(activity)
Discord-->>PresenceHandler: Presence updated
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.env.example:
- Around line 23-31: Reorder the presence-related environment variables so they
follow the expected alphabetical (dotenv-linter) order: move
BOT_PRESENCE_ACTIVITIES above BOT_PRESENCE_STATUS (so BOT_PRESENCE_ACTIVITIES
appears before BOT_PRESENCE_STATUS) and preserve the existing comments and
example block associated with BOT_PRESENCE_ACTIVITIES; update only the
ordering—do not change variable names or comment content.
In `@packages/bot/src/utils/presenceStatus.ts`:
- Around line 98-107: The mapped activity objects currently always include
`fallback: fallback || undefined`, which yields an explicit `undefined` property
and prevents the type predicate in the `.filter((activity): activity is
PresenceActivityTemplate => activity !== null)` from narrowing to
`PresenceActivityTemplate`; update the mapping logic in presenceStatus.ts so
that it returns either `{ type: activityType, template }` when `fallback` is
falsy, or `{ type: activityType, template, fallback }` when `fallback` is a
string, ensuring the returned object shape matches `PresenceActivityTemplate`
and allows the existing type guard to succeed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3b546fd9-aee0-42c9-ba0c-ded5fce130f1
📒 Files selected for processing (9)
.env.exampleCHANGELOG.mdREADME.mddocs/IMPLEMENTATION_STATUS.mdpackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/utils/presenceStatus.tspackages/bot/tests/handlers/clientHandler/presence.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: SonarCloud Scan
🧰 Additional context used
📓 Path-based instructions (21)
{CHANGELOG.md,README.md}
📄 CodeRabbit inference engine (.cursor/rules/agent-rules.mdc)
ALWAYS update CHANGELOG.md and README.md as changes are made.
Files:
README.mdCHANGELOG.md
README.md
📄 CodeRabbit inference engine (.cursor/rules/templates-examples.mdc)
README.md must be updated if behavior changed
Update README.md if behavior changed
Files:
README.md
CHANGELOG.md
📄 CodeRabbit inference engine (.cursor/rules/templates-examples.mdc)
CHANGELOG.md must be updated with all changes in pull requests
Always update CHANGELOG.md with all code changes
Update CHANGELOG.md with all changes, include breaking changes documentation, and reference issues and PRs
Files:
CHANGELOG.md
{CHANGELOG.md,docs/**}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Update
CHANGELOG.mdand relevantdocs/files when behavior or setup changes
Files:
CHANGELOG.mddocs/IMPLEMENTATION_STATUS.md
**/*.{js,jsx,ts,tsx,vue,html}
📄 CodeRabbit inference engine (.cursor/rules/accessibility-openness.mdc)
Provide accessible UI components using semantic HTML and ARIA attributes where necessary
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/utils/presenceStatus.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/dependency-injection.mdc)
**/*.{ts,tsx,js,jsx}: Prefer constructor injection for classes that require dependencies
Avoid global mutable singletons unless necessary
Use explicit interfaces for external dependencies to make testing easier
**/*.{ts,tsx,js,jsx}: Include required references in PRs/code for non-trivial logic: TypeScript (official docs), MDN (JavaScript reference), and official docs for any runtime/framework/libraries used (e.g., Node.js, React) as applicable.
Before assuming behavior of an API, include the doc link and a ≤25-word quote when the change relies on it.
**/*.{ts,tsx,js,jsx}: Prefer named exports for clear usage and easier refactors in TypeScript/JavaScript
Keep import order consistent: external first, then internal modules
Remove dead code and unused imports
**/*.{ts,tsx,js,jsx}: Use PascalCase naming convention for React/UI components
Use camelCase naming convention for variables and functions
Use UPPER_SNAKE_CASE naming convention for constants
Maintain consistent import grouping and ordering within the project, keeping third-party imports separate from local imports
For external data sources (HTTP, database), always validate and sanitize input using type guards or schema validators
**/*.{ts,tsx,js,jsx}: Use Prettier with no semicolons, single quotes, 4-space indent, 80 character width
Files must not exceed 250 lines and this is enforcedImplement TypeScript typecheck and linter in CI quality checks
**/*.{ts,tsx,js,jsx}: Use TypeScript for enhanced type safety
Implement error handling and error logging
Avoid commenting code unless extremely necessary - code should explain itself with descriptive names
Leave NO todos, placeholders or missing pieces in the code
Variables and functions must use camelCase
Constants must use UPPER_SNAKE_CASE
Use arrow functions for methods and computed properties
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements
Maintain consistent import grouping/order: external imports first, then...
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/utils/presenceStatus.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/error-handling.mdc)
**/*.{js,jsx,ts,tsx}: Never throw strings. ThrowError(or typed subclasses) with descriptive messages
Include causal error ascausewhen available for better debugging
Define clear, stable error codes (e.g.,ERR_AUTH_EXPIRED,ERR_NETWORK_TIMEOUT)
Provide optional metadata (e.g.,details,retryable,status,correlationId) in error objects
Use domain error classes per area (e.g.,AuthenticationError,ValidationError,NetworkError)
Log errors with structure (message, code, stack, cause, correlationId, user context where appropriate)
MarkretryablevsnonRetryableerrors where helpful for operations
Set timeouts and handle aborts/cancellations; avoid dangling requests in API/network code
Implement backoff for transient failures; avoid infinite retries
Map HTTP status → domain errors; 4xx vs 5xx behave differently (e.g., retry for 5xx/network)
**/*.{js,jsx,ts,tsx}: Use functional components with hooks in React/React Native. Avoid class components.
Keep components focused on a single responsibility; extract complex logic into custom hooks.
Keep state local when possible. Use Context/Zustand/Redux only when necessary for state management.
If props or state traverse more than 3 levels, consider using context or a feature-scoped store instead of prop drilling.
Use performance optimization techniques:React.memo,useMemo,useCallback,Suspense(web), and virtualization for long lists; avoid unnecessary re-renders.
Web accessibility: use semantic HTML, labels, focus management, keyboard navigation, andaria-*attributes as needed.
React Native accessibility: use accessibility props (accessible,accessibilityLabel), proper roles and labels.
Identify and extract repetitive UI components proactively tocomponents/with clear props and minimal coupling.
Web styles: prefer co-located styles or design system tokens; avoid global style leakage.
React Native styles: preferStyleSheet.create, design tokens, and theme providers; avoid in...
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/utils/presenceStatus.ts
**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/frontend.mdc)
**/*.{test,spec}.{js,jsx,ts,tsx}: Test behavior, not implementation. Prefer Testing Library utilities for testing React/React Native components.
For React Native tests: mock native modules and test component interactions and accessibility labels.
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)
Introduce interfaces at module boundaries to enable testing and substitutions
**/*.{ts,tsx}: Avoid usinganytype in TypeScript. If unavoidable, useunknownwith type guards and justify with a code comment
Preferinterfacefor defining public object shapes in TypeScript, usetypefor unions and utility types
Use TypeScript utility types such asPartial,Pick,Omit,Readonly, andRecordwhen appropriate
UseI{Name}naming convention for interfaces in TypeScript
UseT{Name}naming convention for type aliases and utility types in TypeScript
**/*.{ts,tsx}: Functions must be less than 50 lines with cyclomatic complexity less than 10
Do not useanytypes - ESLint enforces this at error level
**/*.{ts,tsx}: Prefer types over interfaces for most cases
Don't ever useany- type safety always
Avoid enums; use const objects instead
For complex types, create a separate file to declare them and import them
Avoid usinganytype; if unavoidable, useunknownwith type guards and justify with code comment
Preferinterfacefor public API shapes; usetypefor unions and utility types
Use TypeScript utility types (Partial, Pick, Omit, Readonly, Record)
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/utils/presenceStatus.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)
**/*.{test,spec}.{ts,tsx,js,jsx}: Test behavior, not implementation details
Prefer unit tests for core logic; add integration tests at meaningful boundaries
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.ts
**/*.{test,spec}.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/testing-quality.mdc)
**/*.{test,spec}.{js,ts,jsx,tsx}: Use Jest + a React testing library for unit and component tests as applicable
Test behavior, not implementation details
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/documentation.mdc)
**/*.{js,ts,tsx,jsx}: Minimize comments in code; explain the 'why' when non-obvious, let code express the 'what' through clear naming
Document trade-offs briefly when deviating from ideal patterns
**/*.{js,ts,tsx,jsx}: Store secrets, ports, and hosts in environment variables (.env,.env.example) and never hardcode them
Avoid redundant or decorative AI comments; code should be self-explanatory and only commented when logic is non-obvious; prefer refactoring over lengthy commentsNever hardcode secrets, IPs, or ports; use
.envanddocs/for required configuration variables
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/utils/presenceStatus.ts
packages/bot/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/lucky-discord-bot.mdc)
packages/bot/**/*.{ts,tsx}: UseuseMainPlayer()fromdiscord-playerto access the player instance; do not instantiate player directly
Do not duplicate queue or player state outside Discord Player; use shared services from@lucky/sharedfor persistent data like track history and session information
UseerrorLoganddebugLogfrom@lucky/shared/utilsfor logging throughout the bot package
Use embed and reply utilities from@lucky/sharedfor consistent message formatting and error sanitization across the bot
Use services from@lucky/shared(DatabaseService, Redis client) for database and cache access; do not instantiate Prisma or Redis directly in the bot package
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/utils/presenceStatus.ts
packages/bot/**
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
The
botpackage depends onsharedand contains Discord bot commands and player handlers using Discord.js and Discord Player
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/utils/presenceStatus.ts
**/*.{js,mjs,ts,mts}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Use Node.js version ≥22 with ESM (ECMAScript modules) only; no CommonJS
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/utils/presenceStatus.ts
{packages/*/tests/**/*.test.{js,ts},tests/**/*.test.{js,ts}}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Add or adjust unit and integration tests when changing behavior; follow existing patterns in
packages/*/testsand roottests/directories
Files:
packages/bot/tests/handlers/clientHandler/presence.test.ts
**/*.{spec,test}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/quality.mdc)
**/*.{spec,test}.{ts,tsx,js,jsx}: Use Jest for unit and integration tests
Test behavior, not implementation details
Run unit, integration tests, and coverage report in CI quality checks
Files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.ts
packages/bot/src/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/subagent-discord.mdc)
Use
@lucky/sharedfor database, Redis, logging, and embed utilities instead of implementing them locally
Files:
packages/bot/src/handlers/clientHandler/presence.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.tspackages/bot/src/utils/presenceStatus.ts
**/*.spec.ts
📄 CodeRabbit inference engine (.cursor/rules/quality.mdc)
Unit tests must use naming convention
*.spec.ts
Files:
packages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.ts
**/[A-Z]*.{ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
Components must use PascalCase naming
Files:
packages/bot/src/services/MusicPresenceService.spec.ts
**/docs/**/*.{md,mdx}
📄 CodeRabbit inference engine (.cursor/rules/documentation.mdc)
**/docs/**/*.{md,mdx}: Keep API documentation in sync with code changes
Document significant architectural design choices
Files:
docs/IMPLEMENTATION_STATUS.md
🧠 Learnings (10)
📚 Learning: 2026-03-09T20:20:32.245Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/documentation.mdc:0-0
Timestamp: 2026-03-09T20:20:32.245Z
Learning: Applies to README.md : Update README.md if behavior changed
Applied to files:
README.md
📚 Learning: 2026-03-09T20:21:52.065Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-discord.mdc:0-0
Timestamp: 2026-03-09T20:21:52.065Z
Learning: Applies to packages/bot/src/functions/music/commands/**/*.ts : Use `.cursor/skills/music-queue-player/SKILL.md` for play, queue, skip, volume commands and player lifecycle management
Applied to files:
README.mdpackages/bot/src/services/MusicPresenceService.spec.ts
📚 Learning: 2026-03-15T21:57:49.951Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-15T21:57:49.951Z
Learning: When working on music queue/player features (play/queue/skip/volume, player lifecycle), use the `music-queue-player` skill
Applied to files:
README.mddocs/IMPLEMENTATION_STATUS.md
📚 Learning: 2026-03-09T20:21:08.612Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-project.mdc:0-0
Timestamp: 2026-03-09T20:21:08.612Z
Learning: Applies to packages/bot/** : The `bot` package depends on `shared` and contains Discord bot commands and player handlers using Discord.js and Discord Player
Applied to files:
CHANGELOG.md
📚 Learning: 2026-03-09T20:21:08.612Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-project.mdc:0-0
Timestamp: 2026-03-09T20:21:08.612Z
Learning: Applies to {packages/*/tests/**/*.test.{js,ts},tests/**/*.test.{js,ts}} : Add or adjust unit and integration tests when changing behavior; follow existing patterns in `packages/*/tests` and root `tests/` directories
Applied to files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.ts
📚 Learning: 2026-03-09T20:21:38.098Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-backend.mdc:0-0
Timestamp: 2026-03-09T20:21:38.098Z
Learning: Applies to packages/backend/tests/**/*.ts : Follow existing patterns for unit and integration tests in `packages/backend/tests/`
Applied to files:
packages/bot/tests/handlers/clientHandler/presence.test.tspackages/bot/src/handlers/clientHandler/presence.spec.ts
📚 Learning: 2026-03-09T20:21:52.065Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-discord.mdc:0-0
Timestamp: 2026-03-09T20:21:52.065Z
Learning: Applies to packages/bot/src/functions/music/**/*.ts : Use existing voice/queue/guild validators before manipulating player or queue state
Applied to files:
packages/bot/src/services/MusicPresenceService.spec.ts
📚 Learning: 2026-03-09T20:21:31.459Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/quality.mdc:0-0
Timestamp: 2026-03-09T20:21:31.459Z
Learning: Applies to **/*.{spec,test}.{ts,tsx,js,jsx} : Test behavior, not implementation details
Applied to files:
packages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/handlers/clientHandler/presence.spec.ts
📚 Learning: 2026-03-09T20:20:47.877Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-discord-bot.mdc:0-0
Timestamp: 2026-03-09T20:20:47.877Z
Learning: Applies to packages/bot/**/*.{ts,tsx} : Do not duplicate queue or player state outside Discord Player; use shared services from `lucky/shared` for persistent data like track history and session information
Applied to files:
packages/bot/src/services/MusicPresenceService.spec.tspackages/bot/src/utils/presenceStatus.ts
📚 Learning: 2026-03-15T21:57:49.951Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-15T21:57:49.951Z
Learning: When working on unit tests, Jest ESM mocks, or fixing disabled tests, use the `testing-lucky` skill
Applied to files:
packages/bot/src/services/MusicPresenceService.spec.ts
🪛 dotenv-linter (4.0.0)
.env.example
[warning] 31-31: [UnorderedKey] The BOT_PRESENCE_ACTIVITIES key should go before the BOT_PRESENCE_STATUS key
(UnorderedKey)
🪛 GitHub Actions: CI/CD Pipeline
packages/bot/src/utils/presenceStatus.ts
[error] 105-105: TypeScript error TS2677 during typecheck (tsc --noEmit): A type predicate's type must be assignable to its parameter's type.
🔇 Additional comments (6)
packages/bot/src/handlers/clientHandler/presence.ts (6)
1-21: LGTM!Clean imports and type definitions.
MAX_ACTIVITY_NAME_LENGTH = 128correctly captures Discord's activity name limit.
61-77: LGTM!Clean helper functions. Truncation logic correctly ensures the result stays within the 128-character limit (127 chars + 1-char ellipsis).
79-109: LGTM!Fallback logic correctly handles the zero-session edge case by rendering the fallback template when
activeMusicSessions === 0and a fallback is defined. Truncation is properly applied to the final rendered name.
136-160: LGTM!Clean implementation of the rotation control pattern. Proper interval cleanup via
stop(), and the pause/resume mechanism correctly integrates with the caller inservice.ts.
39-59: LGTM!The inline type casting is a pragmatic approach given discord-player's complex internal typing. Null safety is properly handled via optional chaining before iterating.
119-131: This concern is already addressed by the implementation.
getBotPresenceActivities()guarantees a non-empty return value through fallback logic: if no activities are configured (lines 61–62) or if parsing results in an empty array (lines 109–111), it defaults toDEFAULT_PRESENCE_ACTIVITY_TEMPLATES, which is initialized with multiple entries. Therefore,activities.lengthcan never be0, and the modulo operation will not yieldNaN.> Likely an incorrect or invalid review comment.
| return { | ||
| type: activityType, | ||
| template, | ||
| fallback: fallback || undefined, | ||
| } | ||
| }) | ||
| .filter( | ||
| (activity): activity is PresenceActivityTemplate => | ||
| activity !== null, | ||
| ) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Inspect failing predicate site =="
nl -ba packages/bot/src/utils/presenceStatus.ts | sed -n '95,112p'
echo "== Check strict optional-property typing flags in tsconfig files =="
fd -HI "tsconfig*.json" | while read -r file; do
echo "--- ${file} ---"
rg -n "strict|exactOptionalPropertyTypes" "$file" || true
doneRepository: LucasSantana-Dev/Lucky
Length of output: 162
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Check file size =="
wc -l packages/bot/src/utils/presenceStatus.ts
echo "== Read the file around the problem area =="
cat -n packages/bot/src/utils/presenceStatus.ts | sed -n '90,115p'
echo "== Find PresenceActivityTemplate type definition =="
rg -n "type PresenceActivityTemplate|interface PresenceActivityTemplate" packages/bot/Repository: LucasSantana-Dev/Lucky
Length of output: 1120
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Read PresenceActivityTemplate type definition =="
cat -n packages/bot/src/utils/presenceStatus.ts | sed -n '1,30p'
echo "== Check tsconfig settings =="
find . -name "tsconfig*.json" -type f | head -5 | while read -r file; do
echo "--- ${file} ---"
cat "$file" | jq '.compilerOptions | {strict, exactOptionalPropertyTypes, strictNullChecks}' 2>/dev/null || cat "$file"
doneRepository: LucasSantana-Dev/Lucky
Length of output: 2042
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Read full parsePresenceActivityTemplates function =="
cat -n packages/bot/src/utils/presenceStatus.ts | sed -n '60,112p'
echo "== Verify no other issues in the file =="
rg -n "TODO|FIXME|XXX|HACK" packages/bot/src/utils/presenceStatus.ts || echo "No TODOs found"Repository: LucasSantana-Dev/Lucky
Length of output: 2210
Type predicate at line 105 is invalid and blocks CI typecheck
With strict: true in tsconfig, the returned object shape { type, template, fallback: undefined } does not match PresenceActivityTemplate which expects fallback?: string (omitted or a string, not undefined). The type predicate cannot narrow to the correct type.
Apply the proposed fix to create proper object shapes: conditionally return with or without the fallback property instead of always including it with a potential undefined value.
Proposed fix
- .map((entry) => {
+ .map((entry): PresenceActivityTemplate | null => {
const trimmedEntry = entry.trim()
if (!trimmedEntry) return null
@@
- return {
- type: activityType,
- template,
- fallback: fallback || undefined,
- }
+ return fallback
+ ? { type: activityType, template, fallback }
+ : { type: activityType, template }
})
.filter(
(activity): activity is PresenceActivityTemplate =>
activity !== null,
)🧰 Tools
🪛 GitHub Actions: CI/CD Pipeline
[error] 105-105: TypeScript error TS2677 during typecheck (tsc --noEmit): A type predicate's type must be assignable to its parameter's type.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/bot/src/utils/presenceStatus.ts` around lines 98 - 107, The mapped
activity objects currently always include `fallback: fallback || undefined`,
which yields an explicit `undefined` property and prevents the type predicate in
the `.filter((activity): activity is PresenceActivityTemplate => activity !==
null)` from narrowing to `PresenceActivityTemplate`; update the mapping logic in
presenceStatus.ts so that it returns either `{ type: activityType, template }`
when `fallback` is falsy, or `{ type: activityType, template, fallback }` when
`fallback` is a string, ensuring the returned object shape matches
`PresenceActivityTemplate` and allows the existing type guard to succeed.
All issues raised in this CodeRabbit review have been addressed in follow-up commits.
|
Pull request was closed



Summary
BOT_PRESENCE_ACTIVITIESso non-music presence rotation can be customized without changing the default rotation when unsetTest Plan
node ./node_modules/jest/bin/jest.js --config packages/bot/jest.config.cjs packages/bot/src/handlers/clientHandler/presence.spec.ts packages/bot/tests/handlers/clientHandler/presence.test.ts packages/bot/src/services/MusicPresenceService.spec.ts --runInBandNotes
Summary by CodeRabbit
New Features
Documentation