fix(discord): split messages exceeding Discord's 2000 character limit#1001
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue where CoPaw's responses exceeding Discord's 2000-character limit would fail to send. By introducing automatic message chunking, the system can now reliably deliver long responses across multiple messages, ensuring users receive complete information. Additionally, the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully adds message chunking to prevent errors with long messages on Discord. However, it also introduces two critical regressions by removing major features that don't seem related to the main goal of the PR.
Specifically:
- Access Control Removed: The allowlist functionality (
dm_policy,group_policy, etc.) has been completely removed, which could expose the bot to unintended users. - Media Sending Broken: The ability to send media files (images, videos, etc.) has been removed, as the
send_mediamethod implementation is gone.
These changes are not documented in the PR description and should be addressed.
Additionally, I've found an opportunity to simplify the new _chunk_text method by removing some unreachable code, which will improve its readability and maintainability.
|
Please run |
e25d759 to
d2e61be
Compare
e45ea01 to
bd80359
Compare
|
Hi @xieyxclack , I have successfully re-applied the fixes as surgical patches on top of the latest upstream "channel.py" and formatted it. All upstream features (like access control and media sending) are strictly preserved now! Regarding the CI pre-commit failure in #1001, it seems to stem from a Windows CRLF vs LF issue on some unrelated website UI files. Could you please help review the functionality and approve the workflows? Thanks! |
|
@Atletico1999 Of course! Thank you very much for your contribution :) |
|
@Atletico1999 Hi, Thanks for the pr! I reviewed the code and found some tiny issues.
This is a common long-message scenario (code explanations). Consider tracking fence state during chunking:
This would keep code blocks properly formatted across split messages. If you don't mind, I can help you fix the above issues and check it together. If you have any better suggestions, feel free to discuss. |
|
Hi @Leirunlin , thanks for the detailed review! Regarding the three issues:
I also noticed #1073 covers the same problem and brought up some good points (tests, lint). If it makes sense, I can incorporate those improvements (tests + the explicit Will push the encoding fixes shortly. |
Discord's API rejects messages longer than 2000 characters. When CoPaw generates a long response (code blocks, detailed explanations), the send() call fails with 400 Bad Request. Changes: - Add _DISCORD_MAX_LEN class constant (2000) - Add _chunk_text() static method that splits at newline boundaries with code-fence awareness: tracks open/close of markdown fences so split chunks keep code blocks properly formatted - Modify send() to loop over chunks instead of sending raw text - Use compiled _FENCE_RE regex for reliable fence detection All upstream features (access control, media sending, allowlist) are strictly preserved — no unrelated modifications.
bd80359 to
cae7724
Compare
|
Hi @Atletico1999, thanks again for the PR and for iterating so quickly. We’d like to use your implementation as the base, so you can just keep updating this PR. If either BOM / duplicate coding line or corruption is annoying to fix on your side, you can leave it to me. Once 3) fence-aware chunking is added, I’m happy to take another review pass. |
|
Hi @Leirunlin , thanks for making this the base! I just force-pushed a clean version that includes all three fixes:
Sorry for the initial encoding mess 😅. It's fully clean and ready for your review whenever you get a chance! |
|
Great! I have tested the new commit locally and it looks good to me. |
Welcome to CoPaw! 🎉Thank you @Atletico1999 for your first contribution! Your PR has been merged. 🚀 We'd love to give you a shout-out in our release notes! If you're comfortable sharing, please reply to this comment with your social media handles using the format below:
Thanks again for helping make CoPaw better! |
Description
Discord's API rejects messages longer than 2000 characters. When CoPaw generates a long response (e.g. code blocks, detailed explanations), the send() call fails with 400 Bad Request, leaving the user with no reply.
This PR adds automatic message chunking to DiscordChannel:
_DISCORD_MAX_LENclass constant (2000 chars)_chunk_text()static method that splits at newline boundaries to preserve markdown formatting._FENCE_RE. If a chunk splits in the middle of a code block, it automatically appends a closing fence to the current message and prepends an opening fence to the next message. This ensures code syntax highlighting is never broken across messages.Related Issue: N/A (discovered in production)
Security Considerations: None — only affects outbound message formatting.
Type of Change
Component(s) Affected
Checklist
pre-commit run --all-fileslocally and it passespytestor as relevant) and they passTesting
Additional Notes