Skip to content

Conversation

@MaxymMelnychuk
Copy link

@MaxymMelnychuk MaxymMelnychuk commented Jul 1, 2025

This update limits the use of bot commands to designated text channels only. Users will no longer be able to execute commands outside these specified channels, helping to keep the server organized and reduce command misuse.

Summary by CodeRabbit

  • New Features
    • Commands and message interactions are now restricted to specific allowed channels in the Discord bot. Users will receive an error message if they attempt to use commands or send messages in unauthorized channels.
  • Chores
    • Improved and expanded .gitignore files for better coverage and organization.
    • Added a .gitignore to the Discord directory to protect environment files.
    • Updated package.json files to include workspace configuration, JSON schema reference, and development dependencies.
    • Updated TypeScript configuration to allow implicit any types.
  • Style
    • Adjusted import sources for motion components in the website UI for consistency.
  • Documentation
    • Modified markdown metadata for rule documentation.

@coderabbitai
Copy link

coderabbitai bot commented Jul 1, 2025

Walkthrough

Channel validation logic was introduced in the Discord bot, restricting certain commands and message responses to specific channels. This was achieved by adding guard functions and integrating them into relevant feature modules. Additional changes include improvements to monorepo configuration, dependency management, TypeScript settings, motion library imports, and minor formatting and metadata updates across various files.

Changes

Files / Groups Change Summary
.gitignore, discord/.gitignore Expanded and reorganized ignore rules; added .env ignore in discord.
package.json Converted to monorepo config, added workspaces, devDependencies, and fixed scripts section.
discord/package.json Added JSON schema reference and formatting tweaks.
discord/tsconfig.json Disabled TypeScript's noImplicitAny check.
discord/src/core/guards/text-channel.ts Introduced isInAllowedChannel and sendChannelError guard functions for channel validation.
discord/src/features/gm-streak/leaderboard.ts,
.../registrer.ts,
.../streak.ts,
.../test/index.ts
Integrated channel guards to restrict command/message handling to allowed channels, with user feedback on errors.
website/components/ui/floating-dock.tsx Changed motion library imports from motion/react to framer-motion.
.cursor/rules/next-best-practices.mdc Added duplicated frontmatter block with different alwaysApply metadata.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Discord
    participant Bot
    participant Guards

    User->>Discord: Sends message or command
    Discord->>Bot: Triggers event handler
    Bot->>Guards: isInAllowedChannel(entity)
    alt In allowed channel
        Guards-->>Bot: true
        Bot->>Bot: Process command/message
    else Not in allowed channel
        Guards-->>Bot: false
        Bot->>Guards: sendChannelError(entity)
        Guards->>User: Send error message
        Bot->>Bot: Abort further processing
    end
Loading

Poem

In channels where bunnies hop and play,
New rules now guide what bots can say.
If you stray from the chosen lane,
A gentle error will explain.
Monorepo roots and configs bloom,
While rabbits dance from room to room! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c10b87 and a24f177.

📒 Files selected for processing (1)
  • .cursor/rules/next-best-practices.mdc (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .cursor/rules/next-best-practices.mdc

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (2)
discord/package.schema.json (1)

1-10: Vendoring a 1 300-line package.json schema inflates the repo and adds maintenance overhead

Unless you plan to fork and evolve the schema, you can reference the canonical copy hosted on schemastore.org instead of duplicating it:

-  "$schema": "http://json-schema.org/draft-07/schema#",
-  "title": "JSON schema for NPM package.json files",
+  "$schema": "http://json-schema.org/draft-07/schema#",
+  "$ref": "https://json.schemastore.org/package.json",

This keeps the repo slim (~40 KB saved) and automatically benefits from upstream updates.

If a local copy is mandatory (e.g., offline CI), consider importing the file via a git submodule or automated sync script to avoid drift.

discord/src/core/guards/text-channel.ts (1)

11-25: Consider supporting multiple allowed channels.

The current implementation only supports a single allowed channel. For better flexibility, consider supporting multiple channels.

-const ALLOWED_CHANNEL_ID = "1296547272569651250";
+const ALLOWED_CHANNEL_IDS = new Set([
+  "1296547272569651250", // Main commands channel
+  // Add more channel IDs as needed
+]);

export async function isInvalidChannel(entity: Message | CommandInteraction): Promise<boolean> {
-  if (entity.channel?.type !== ChannelType.GuildText || entity.channel.id !== ALLOWED_CHANNEL_ID) {
+  if (entity.channel?.type !== ChannelType.GuildText || !ALLOWED_CHANNEL_IDS.has(entity.channel.id)) {
-    const reply = `Rooooaaarrr!! I can only execute commands in the channel <#${ALLOWED_CHANNEL_ID}>.`;
+    const channelMentions = Array.from(ALLOWED_CHANNEL_IDS).map(id => `<#${id}>`).join(', ');
+    const reply = `Rooooaaarrr!! I can only execute commands in these channels: ${channelMentions}.`;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66054da and 742481a.

⛔ Files ignored due to path filters (4)
  • discord/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • package-lock.json is excluded by !**/package-lock.json
  • website/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (12)
  • .gitignore (1 hunks)
  • discord/package.json (1 hunks)
  • discord/package.schema.json (1 hunks)
  • discord/src/core/guards/text-channel.ts (1 hunks)
  • discord/src/features/gm-streak/leaderboard.ts (2 hunks)
  • discord/src/features/gm-streak/registrer.ts (1 hunks)
  • discord/src/features/gm-streak/streak.ts (2 hunks)
  • discord/src/features/test/index.ts (1 hunks)
  • discord/tsconfig.json (1 hunks)
  • package.json (1 hunks)
  • rules/next-best-practices.mdc (1 hunks)
  • website/components/ui/floating-dock.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
discord/src/features/test/index.ts (1)
discord/src/core/guards/text-channel.ts (1)
  • isInvalidChannel (11-25)
discord/src/features/gm-streak/streak.ts (1)
discord/src/core/guards/text-channel.ts (1)
  • isInvalidChannel (11-25)
discord/src/features/gm-streak/leaderboard.ts (1)
discord/src/core/guards/text-channel.ts (1)
  • isInvalidChannel (11-25)
discord/src/features/gm-streak/registrer.ts (1)
discord/src/core/guards/text-channel.ts (1)
  • isInvalidChannel (11-25)
🔇 Additional comments (7)
discord/package.json (1)

2-2: Validate $schema path portability

"$schema": "./package.schema.json" works from the file location, but tools that resolve the manifest from different CWDs (e.g. npm pkg, editors, some CI steps) may fail to locate the schema.

Consider making it project-root-relative or embedding the absolute URL from the repo:

-  "$schema": "./package.schema.json",
+  "$schema": "file:discord/package.schema.json",

Alternatively host the schema at a URL and reference that.

website/components/ui/floating-dock.tsx (1)

6-13: framer-motion dependency already declared
Verified that package.json includes
• "framer-motion": "^12.19.2"
No changes needed.

discord/src/features/gm-streak/streak.ts (1)

5-5: LGTM! Clean implementation of channel restriction.

The channel guard is properly imported and applied at the right point in the command flow, ensuring early termination when commands are executed in restricted channels.

Also applies to: 21-21

discord/src/features/test/index.ts (1)

2-2: LGTM! Consistent implementation with proper async handling.

The message handler correctly transitions to async and applies the channel guard before processing the message content.

Also applies to: 4-4, 6-6

discord/src/features/gm-streak/leaderboard.ts (1)

2-2: LGTM! Consistent channel guard implementation.

The guard is properly placed to prevent expensive database operations and user fetching when commands are executed in restricted channels.

Also applies to: 22-22

discord/src/features/gm-streak/registrer.ts (1)

2-2: LGTM! Proper channel restriction for streak registration.

The channel guard correctly prevents "gm" streak registration from unauthorized channels, maintaining the integrity of the streak system.

Also applies to: 8-8

.gitignore (1)

1-12: LGTM! Improved .gitignore organization and coverage.

The reorganization with clear categories and comments improves maintainability, and the new entries (.pnpm/, .next/, out/, discord/.env) properly cover modern development tooling and project-specific files.

Comment on lines 1 to 10
---
description:
globs:
alwaysApply: false
---
---
description:
globs:
alwaysApply: true
---
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Duplicate front-matter blocks will confuse Markdown/MDX tooling

There are two consecutive --- front-matter sections (lines 1-5 and 6-10). Most MDX/markdown processors pick only the first, silently discarding or mis-merging the second, which means the intended metadata (alwaysApply: true) may never be read.

---
-description: 
-globs: 
-alwaysApply: false
---
----
-description: 
-globs: 
-alwaysApply: true
---
+# Merge the desired keys into ONE front-matter block
+---
+description: "Best-practices for Next.js codebase"
+globs: []
+alwaysApply: true
+---

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In rules/next-best-practices.mdc at lines 1 to 10, there are two consecutive
front-matter blocks which can cause Markdown/MDX processors to ignore the second
block. To fix this, merge the two front-matter sections into a single block
containing all the intended metadata, including alwaysApply: true, ensuring only
one front-matter block is present at the top of the file.

Copy link
Member

@Kan-A-Pesh Kan-A-Pesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le code marche surement mais il y a pleins d'erreurs et de choix illogique. rendant la codebase legacy (code non utilisé, fichiers dupliqués, etc...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est une fichier que tu dois récup avec une url de base pas download

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem, il doit etre recup en ligne et en général il est pas nécéssaire


# Environment variables (sensitive info)
.env
discord/.env
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

si c'est spécifique c'est mieux de mettre un gitignore dans le dossier discord directement

Comment on lines +15 to +19
if (entity instanceof Message) {
await entity.reply(reply);
} else {
await entity.reply({ content: reply, ephemeral: true });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi ce check ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

également comme le dit le Lapin pourquoi executer des actions dans un code censé être une fonction de check

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi avoir laissé ce fichier a la racine ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi avoir ajouté des dépendances à ce fichier s'il est a la racine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le fichier est pas pris en compte s'il est juste dans rules il faut le mettre dans .cursor/rules

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi avoir un package-lock, un pnpm-lock ET un yarn.lock, il faut choisir un package manager et pas en installer trois xD

yarn.lock Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi avoir un package-lock, un pnpm-lock ET un yarn.lock, il faut choisir un package manager et pas en installer trois xD

coderabbitai bot added a commit that referenced this pull request Jul 2, 2025
Docstrings generation was requested by @MaxymMelnychuk.

* #3 (comment)

The following files were modified:

* `discord/src/core/guards/text-channel.ts`
@coderabbitai
Copy link

coderabbitai bot commented Jul 2, 2025

Note

Generated docstrings for this pull request at #4

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
discord/src/core/guards/text-channel.ts (1)

8-11: Consider adding null safety for edge cases.

While the current implementation works for typical Discord scenarios, consider adding explicit null checks for additional safety.

 export function isInAllowedChannel(entity: Message | CommandInteraction): boolean {
-  return entity.channel?.type === ChannelType.GuildText &&
-    entity.channel.id === ALLOWED_CHANNEL_ID;
+  return entity.channel?.type === ChannelType.GuildText && 
+    entity.channel?.id === ALLOWED_CHANNEL_ID;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c26e3d6 and 8c10b87.

⛔ Files ignored due to path filters (2)
  • discord/package-lock.json is excluded by !**/package-lock.json
  • website/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • .cursor/rules/next-best-practices.mdc (1 hunks)
  • discord/.gitignore (1 hunks)
  • discord/src/core/guards/text-channel.ts (1 hunks)
  • discord/src/features/gm-streak/leaderboard.ts (2 hunks)
  • discord/src/features/gm-streak/registrer.ts (1 hunks)
  • discord/src/features/gm-streak/streak.ts (2 hunks)
  • discord/src/features/test/index.ts (1 hunks)
  • package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • discord/.gitignore
🚧 Files skipped from review as they are similar to previous changes (5)
  • discord/src/features/gm-streak/registrer.ts
  • discord/src/features/test/index.ts
  • package.json
  • discord/src/features/gm-streak/leaderboard.ts
  • discord/src/features/gm-streak/streak.ts
🔇 Additional comments (3)
discord/src/core/guards/text-channel.ts (3)

3-3: LGTM: Environment variable configuration implemented.

Good implementation using environment variables with a fallback value, addressing the previous hardcoded concern.


8-11: LGTM: Clean separation of validation logic.

The pure validation function correctly implements the channel check without side effects, addressing the previous concern about mixing validation with messaging.


16-27: LGTM: Robust error handling implementation.

The function properly handles both Message and CommandInteraction types and includes comprehensive error handling to prevent bot crashes, addressing all previous feedback.

Comment on lines 1 to 9
---
description:
globs:
alwaysApply: false
---
description:
globs:
alwaysApply: true
---
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix duplicate YAML frontmatter blocks.

The file contains two YAML frontmatter blocks with conflicting alwaysApply values. This is likely a configuration error that could cause parsing issues or unexpected behavior.

Remove the duplicate frontmatter and keep only one block:

----
-description: 
-globs: 
-alwaysApply: false
----
 description: 
 globs: 
 alwaysApply: true
 ---

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In .cursor/rules/next-best-practices.mdc at lines 1 to 9, there are two YAML
frontmatter blocks with conflicting alwaysApply values. Remove one of the
duplicate frontmatter blocks entirely so that only a single YAML frontmatter
block remains at the top of the file, ensuring consistent configuration and
preventing parsing errors.

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.

2 participants