-
Notifications
You must be signed in to change notification settings - Fork 1
Restrict commands to specific text channels #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Restrict commands to specific text channels #3
Conversation
WalkthroughChannel 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
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
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 overheadUnless 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
⛔ Files ignored due to path filters (4)
discord/pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlpackage-lock.jsonis excluded by!**/package-lock.jsonwebsite/pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlyarn.lockis 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$schemapath 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 thatpackage.jsonincludes
• "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.
rules/next-best-practices.mdc
Outdated
| --- | ||
| description: | ||
| globs: | ||
| alwaysApply: false | ||
| --- | ||
| --- | ||
| description: | ||
| globs: | ||
| alwaysApply: true | ||
| --- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
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.
Kan-A-Pesh
left a comment
There was a problem hiding this 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...)
discord/package.schema.json
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
| if (entity instanceof Message) { | ||
| await entity.reply(reply); | ||
| } else { | ||
| await entity.reply({ content: reply, ephemeral: true }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pourquoi ce check ?
There was a problem hiding this comment.
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
package-lock.json
Outdated
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
rules/next-best-practices.mdc
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Docstrings generation was requested by @MaxymMelnychuk. * #3 (comment) The following files were modified: * `discord/src/core/guards/text-channel.ts`
|
Note Generated docstrings for this pull request at #4 |
There was a problem hiding this 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
⛔ Files ignored due to path filters (2)
discord/package-lock.jsonis excluded by!**/package-lock.jsonwebsite/package-lock.jsonis 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.
| --- | ||
| description: | ||
| globs: | ||
| alwaysApply: false | ||
| --- | ||
| description: | ||
| globs: | ||
| alwaysApply: true | ||
| --- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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