Skip to content

Conversation

@fernanduandrade
Copy link

@fernanduandrade fernanduandrade commented Nov 30, 2025

Bug Fixes

  • fix

    • Unintended bot replies across all Discord channels by restricting greeting responses to a specific channel ID.
    • Implemented channel filtering using an environment variable (DISCORD_GENEREAL_CHAT_ID) to ensure responses occur only in the configured channel.
  • chores

    • Added .env configuration key for allowed Discord channel.
    • Updated command handler to load channel configuration via env().

Summary by CodeRabbit

  • Chores

    • Added DISCORD_GENERAL_CHAT_ID to environment example and added corresponding Discord service configuration.
  • Bug Fixes

    • Message handling now checks the configured channel ID and only processes messages from that channel.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 30, 2025

Walkthrough

Adds a new env entry DISCORD_GENERAL_CHAT_ID, exposes discord.general_chat_id in configuration, and gates GreetingsEvent to only proceed when the incoming message's channel_id matches the configured general chat ID.

Changes

Cohort / File(s) Summary
Env example
/.env.example
Appends DISCORD_GENERAL_CHAT_ID= line (adds the correctly spelled variable).
Configuration
config/services.php
Adds discord.general_chat_id configuration sourced from the DISCORD_GENERAL_CHAT_ID environment variable.
Event handler
app-modules/bot-discord/src/Events/GreetingsEvent.php
Reads config('services.discord.general_chat_id') into $allowedChannel and returns early if $message->channel_id !== $allowedChannel, gating processing to that channel.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify .env.example uses DISCORD_GENERAL_CHAT_ID (no remaining misspellings).
  • Ensure discord.general_chat_id config value type/format matches Message->channel_id (string vs int) and consider casting or strictness.
  • Confirm behavior when the config value is empty/null (should it allow all channels or block all).
  • Consider config:cache and deployment ordering for the new env var.

Poem

🐰 I sniffed a name upon a line,
A channel marked for chat and time,
I guard the gate, I hop — I pause,
Await the call that meets the cause,
Then share a nibble of sunny rhyme 🌿

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding validation to restrict greeting replies to the general chat channel only.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 4

🧹 Nitpick comments (1)
.env.example (1)

79-79: Address static analysis hints for consistency.

Consider the following cosmetic improvements:

  • Add a blank line at the end of the file
  • Move DISCORD_GENERAL_CHAT_ID before DISCORD_TOKEN to maintain alphabetical ordering within the Discord configuration section

Apply this diff:

 TWITCH_OAUTH_CLIENT_SECRET=
 TWITCH_OAUTH_REDIRECT_URI=
 
-DISCORD_TOKEN=
 DISCORD_GENERAL_CHAT_ID=
+DISCORD_TOKEN=
+
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d95bda and a14cd70.

📒 Files selected for processing (2)
  • .env.example (1 hunks)
  • app-modules/bot-discord/src/Events/GreetingsEvent.php (1 hunks)
🧰 Additional context used
🪛 dotenv-linter (4.0.0)
.env.example

[warning] 79-79: [EndingBlankLine] No blank line at the end of the file

(EndingBlankLine)


[warning] 79-79: [UnorderedKey] The DISCORD_GENEREAL_CHAT_ID key should go before the DISCORD_TOKEN key

(UnorderedKey)

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: 0

🧹 Nitpick comments (1)
app-modules/bot-discord/src/Events/GreetingsEvent.php (1)

30-33: Channel guard via config looks correct; consider normalizing types and logging misconfigurations.

Reading the general chat ID from config('services.discord.general_chat_id') and gating early keeps the greetings scoped to the intended channel and avoids the previous env()/non‑strict comparison issues.

Two small, optional refinements:

  • Ensure $message->channel_id and the config value are the same scalar type (both strings or both ints); otherwise !== will always fail. If there’s any chance of mismatch, normalize both sides (e.g. cast to string) before comparing:
-        $allowedChannel = config('services.discord.general_chat_id');
-        if ($message->channel_id !== $allowedChannel) {
+        $allowedChannel = config('services.discord.general_chat_id');
+        if ((string) $message->channel_id !== (string) $allowedChannel) {
             return;
         }
  • Optionally, if general_chat_id is not configured (null/empty), you could log a warning once so it’s clear why greetings are never sent.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80aa88d and d544413.

📒 Files selected for processing (1)
  • app-modules/bot-discord/src/Events/GreetingsEvent.php (1 hunks)

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: 0

🧹 Nitpick comments (1)
.env.example (1)

78-79: Reorder environment variables and add trailing newline.

The static analysis tool flags two minor issues:

  1. DISCORD_GENERAL_CHAT_ID should be ordered alphabetically before DISCORD_TOKEN
  2. The file is missing a blank line at the end

Apply this diff to correct both issues:

 TWITCH_OAUTH_SCOPES=
 TWITCH_OAUTH_CLIENT_ID=
 TWITCH_OAUTH_CLIENT_SECRET=
 TWITCH_OAUTH_REDIRECT_URI=
 
-DISCORD_TOKEN=
-DISCORD_GENERAL_CHAT_ID=
+DISCORD_GENERAL_CHAT_ID=
+DISCORD_TOKEN=

Ensure you also add a newline after line 79.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d544413 and 42193c9.

📒 Files selected for processing (1)
  • .env.example (1 hunks)
🧰 Additional context used
🪛 dotenv-linter (4.0.0)
.env.example

[warning] 79-79: [EndingBlankLine] No blank line at the end of the file

(EndingBlankLine)


[warning] 79-79: [UnorderedKey] The DISCORD_GENERAL_CHAT_ID key should go before the DISCORD_TOKEN key

(UnorderedKey)

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.

3 participants