-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Discord Bot - "Ignore Bot Messages" Flag in New Message Triggers #17290
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
WalkthroughThe changes introduce an optional "Ignore Bot Messages" flag to several Discord bot trigger sources, enabling users to filter out messages sent by the configured bot itself. Supporting methods for retrieving and storing the bot's ID, as well as fetching the bot profile, are added to the shared common module. Version numbers and import paths are also updated. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Source (Trigger)
participant Common Module
participant Discord API
User->>Source (Trigger): Enable "Ignore Bot Messages" flag
Source (Trigger)->>Common Module: deploy() - getBotProfile()
Common Module->>Discord API: GET /users/@me
Discord API-->>Common Module: Bot profile (ID)
Common Module-->>Source (Trigger): Bot ID
loop On new message event
Source (Trigger)->>Common Module: _getBotId()
Source (Trigger)->>Discord API: Fetch new messages
Discord API-->>Source (Trigger): Messages
Source (Trigger)->>Source (Trigger): Filter out messages from bot ID if flag enabled
Source (Trigger)->>User: Emit event(s) for non-bot messages
end
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes were found. Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
components/discord_bot/sources/new-forum-thread-message/new-forum-thread-message.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs components/discord_bot/sources/common/common.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs components/discord_bot/sources/new-thread-message/new-thread-message.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
✨ Finishing Touches
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: 0
🧹 Nitpick comments (1)
components/discord_bot/sources/common/common.mjs (1)
26-30: Consider adding error handling for Discord API call.The
getBotProfile()method correctly uses the Discord API endpoint/users/@me. However, consider adding error handling since this method will be called during the deploy hook, and API failures could prevent proper initialization.getBotProfile() { - return this.discord._makeRequest({ - path: "/users/@me", - }); + try { + return this.discord._makeRequest({ + path: "/users/@me", + }); + } catch (error) { + console.error("Failed to fetch bot profile:", error); + throw error; + } },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
components/discord_bot/package.json(1 hunks)components/discord_bot/sources/common/common.mjs(2 hunks)components/discord_bot/sources/new-forum-thread-message/new-forum-thread-message.mjs(5 hunks)components/discord_bot/sources/new-guild-member/new-guild-member.mjs(2 hunks)components/discord_bot/sources/new-message-in-channel/new-message-in-channel.mjs(4 hunks)components/discord_bot/sources/new-tag-added-to-thread/new-tag-added-to-thread.mjs(2 hunks)components/discord_bot/sources/new-thread-message/new-thread-message.mjs(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
- GitHub Check: Verify TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (24)
components/discord_bot/package.json (1)
3-3: LGTM: Appropriate version bump for new feature.The version increment from 0.6.1 to 0.6.2 correctly reflects the addition of the new "ignore bot messages" functionality across multiple source files.
components/discord_bot/sources/new-guild-member/new-guild-member.mjs (2)
2-2: LGTM: Import path correctly updated for refactored structure.The import path change from
"../common.mjs"to"../common/common.mjs"aligns with the code organization improvements across the Discord bot sources.
11-11: LGTM: Version increment follows semantic versioning.The version bump from 0.1.4 to 0.1.5 appropriately reflects the structural changes to the import paths.
components/discord_bot/sources/new-tag-added-to-thread/new-tag-added-to-thread.mjs (2)
2-2: LGTM: Consistent import path refactoring.The import path update aligns with the broader structural improvements being made across the Discord bot source files.
11-11: LGTM: Appropriate version increment.Version bump correctly reflects the import path changes made to the file.
components/discord_bot/sources/common/common.mjs (2)
1-2: LGTM: Import paths correctly updated for new directory structure.The updated import paths properly reference the parent directories after the common module restructuring.
20-25: LGTM: Bot ID database management methods are well-implemented.The
_getBotId()and_setBotId()methods follow consistent patterns with existing database operations and use appropriate key naming.components/discord_bot/sources/new-thread-message/new-thread-message.mjs (6)
3-3: LGTM: Import path correctly updated.The import path change aligns with the common module restructuring across the codebase.
12-12: LGTM: Version increment appropriate for new feature.Version bump from 0.0.5 to 0.0.6 correctly reflects the addition of the ignore bot messages functionality.
23-28: LGTM: Well-designed optional prop for bot message filtering.The
ignoreBotMessagesprop is properly configured as an optional boolean with clear labeling and description. The implementation maintains backward compatibility.
30-36: LGTM: Efficient deploy hook implementation.The deploy hook correctly fetches and stores the bot ID only when the feature is enabled, avoiding unnecessary API calls when the feature is disabled.
41-43: LGTM: Clean bot ID retrieval logic.The conditional retrieval of bot ID is efficient and follows the expected pattern for optional feature implementation.
101-103: LGTM: Correct message filtering implementation.The filtering logic properly excludes messages authored by the bot when the feature is enabled. The placement after message retrieval but before emission is optimal for performance.
components/discord_bot/sources/new-forum-thread-message/new-forum-thread-message.mjs (6)
4-4: LGTM: Import path correction looks good.The import path change to the more specific subdirectory structure aligns with the described refactoring.
13-13: LGTM: Version increment is appropriate.The version bump from 0.0.4 to 0.0.5 is suitable for this minor feature addition.
38-43: LGTM: Well-defined optional property.The
ignoreBotMessagesprop is properly configured with appropriate type, label, description, and marked as optional.
64-66: LGTM: Efficient bot ID retrieval pattern.The conditional bot ID retrieval is implemented efficiently, fetching the ID only once per run when needed.
133-135: LGTM: Optimal filtering placement.The message filtering is strategically placed after retrieval but before expensive channel enrichment operations, which optimizes performance by avoiding unnecessary API calls for bot messages.
45-51: To locate these method definitions more reliably, let’s search the entire repo (including arrow‐function and async variants):#!/bin/bash # Search for any definition or assignment of getBotProfile and _setBotId rg -n "getBotProfile" . rg -n "_setBotId" . rg -n "async getBotProfile" . rg -n "getBotProfile\s*=" . rg -n "_setBotId\s*=" .components/discord_bot/sources/new-message-in-channel/new-message-in-channel.mjs (5)
3-3: LGTM: Consistent import path update.The import path change matches the pattern established in the other Discord bot sources.
14-14: LGTM: Appropriate version increment.Version bump from 0.0.18 to 0.0.19 is suitable for this feature addition.
39-44: LGTM: Consistent property definition.The
ignoreBotMessagesprop definition matches the implementation in other Discord bot sources, maintaining consistency across the codebase.
52-58: LGTM: Consistent deploy hook implementation.The deploy hook follows the same pattern as other Discord bot sources and properly handles the conditional bot ID retrieval and storage.
116-118: LGTM: Efficient message filtering implementation.The filtering logic is correctly implemented and placed optimally before event emission to avoid processing unnecessary bot messages.
luancazarine
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.
Hi @michelle0927, LGTM! Ready for QA!
Resolves #17200
Summary by CodeRabbit
New Features
Bug Fixes
Chores