Skip to content

[codex] Support Discord DM agent requests#305

Open
michaelmwu wants to merge 1 commit into
mainfrom
michaelmwu/support-discord-dms
Open

[codex] Support Discord DM agent requests#305
michaelmwu wants to merge 1 commit into
mainfrom
michaelmwu/support-discord-dms

Conversation

@michaelmwu
Copy link
Copy Markdown
Member

Summary

  • Allow natural-language agent requests sent directly to the Discord bot by DM.
  • Resolve DM senders against the configured 508 guild before forwarding to the backend, using fresh guild member roles in the agent context.
  • Refuse DM workflows for users who are no longer in the configured guild, including stale confirmation flows.
  • Document that DM support applies to text messages, while slash-command DM support remains separate.

Validation

  • uv run pytest tests/unit/test_agent_cog.py
  • ./scripts/lint.sh
  • ./scripts/mypy.sh
  • ./scripts/test.sh

Copilot AI review requested due to automatic review settings May 24, 2026 23:35
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

Warning

Review limit reached

@michaelmwu, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 22 minutes and 38 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20da877f-c820-4a61-bc20-42cb7eedf4ec

📥 Commits

Reviewing files that changed from the base of the PR and between b9cd975 and 6569528.

📒 Files selected for processing (5)
  • apps/discord_bot/README.md
  • apps/discord_bot/src/five08/discord_bot/bot.py
  • apps/discord_bot/src/five08/discord_bot/cogs/agent.py
  • tests/unit/test_agent_cog.py
  • tests/unit/test_bot.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch michaelmwu/support-discord-dms

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

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for handling natural-language agent requests sent to the Discord bot via direct messages (DMs), while ensuring DM senders are validated as current members of the configured 508 Discord server and that confirmation flows reflect up-to-date membership/roles.

Changes:

  • Add DM handling path to the agent message listener, resolving DM senders against the configured guild and using fresh guild-member roles in the backend context.
  • Update confirmation-context role behavior to distinguish “guild not resolvable” vs “member no longer present,” clearing roles when the member has left the guild.
  • Extend unit tests and update Discord bot documentation to cover DM behavior and guardrails.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/unit/test_agent_cog.py Adds coverage for DM agent requests, DM denial for non-members, and confirmation-context role clearing when a member leaves the guild.
apps/discord_bot/src/five08/discord_bot/cogs/agent.py Implements DM request handling, guild/member resolution, role refresh semantics in confirmations, and DM-specific response routing/auditing.
apps/discord_bot/README.md Documents DM support for text-based agent requests and the membership validation requirement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +372 to +376
metadata={"reason": "member_not_in_configured_guild"},
)
await message.reply(
"I can only run DM workflows for current members of the "
"configured 508 server.",
Comment on lines +966 to +976
configured_guild_id = str(settings.discord_server_id or "").strip()
if configured_guild_id:
try:
return self.bot.get_guild(int(configured_guild_id))
except ValueError:
return None

guilds = getattr(self.bot, "guilds", [])
if len(guilds) == 1:
return guilds[0]
return None
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad8db68579

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +366 to +367
member_context = await self._resolve_dm_member_context(message.author.id)
if member_context is None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Rate-limit DM requests before guild member resolution

Move the DM rate-limit check ahead of _resolve_dm_member_context in _handle_agent_dm: right now every DM from a non-member (or from a member before cache hit) can trigger a guild member lookup/fetch, and those denied requests are not throttled because _mention_rate_limited runs only after successful membership resolution. In a spam scenario this creates an unbounded stream of Discord API lookups and denial replies, which can consume rate budget and degrade legitimate bot traffic.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6569528889

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +253 to +254
slash_context = await self._resolve_slash_context(interaction)
if slash_context is None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Rate-limit DM slash requests before member resolution

The new DM slash flow performs self._resolve_slash_context(interaction) immediately, which for DM users calls _resolve_dm_member_context and can hit guild.fetch_member on every request, but this path has no throttling equivalent to _mention_rate_limited. In practice, a user outside the configured guild (or a cached-miss user) can spam /agent in DMs and force repeated Discord member lookups before denial, consuming API budget and degrading legitimate bot traffic.

Useful? React with 👍 / 👎.

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