Skip to content
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

Handle embeds larger than the character limit #86

Open
Kevin-Roman opened this issue Sep 16, 2023 · 2 comments
Open

Handle embeds larger than the character limit #86

Kevin-Roman opened this issue Sep 16, 2023 · 2 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Kevin-Roman
Copy link
Contributor

Kevin-Roman commented Sep 16, 2023

Description

Using /problem, any problem that leads to an embed size of more than 6000 characters in total, alongside per field character restrictions, cannot be sent. These restrictions are documented here: https://www.pythondiscord.com/pages/guides/python-guides/discord-embed-limits/. An example of such question is LeetCode problem 1070.

Potential solutions

  1. Firstly, the total embed character size needs to be checked (https://discord.com/developers/docs/resources/channel#embed-object-embed-structure) alongside the sizes of the header/description/footer/fields/etc...
  2. Either:
    • Split the embed appropriately and send multiple embeds.
    • Or, determine which fields are too long (or make the total embed go over 6000 characters) and just don't include them in the embed, as the most important part of the question is its description.

    I prefer the latter just because one single embed looks cleaner and is shorter (and requires less Discord API usage), but it can be something to discuss and share opinions on.

  3. Send the multiple embeds, or the filtered embed (depending on the approach selected)

Where to start

  1. The question embed logic is in ./ui/embeds/problems.py - question_embed
  2. Create a function that splits/filters (based on the selected approach) an embed, that calculates the size of each section in the embed and the total size.
  3. Then check each character size against the limits.
  4. Appropriately modify the embed if necessary.
@Kevin-Roman Kevin-Roman changed the title Error if question embed is longer than 1024 bytes. Error if question embed is longer than 1024 bytes Sep 16, 2023
@Kevin-Roman Kevin-Roman added the bug Something isn't working label Sep 16, 2023
@Kevin-Roman Kevin-Roman changed the title Error if question embed is longer than 1024 bytes Handle embeds larger than the character limit May 22, 2024
@Kevin-Roman Kevin-Roman added the good first issue Good for newcomers label Jun 7, 2024
@LiamGlasson LiamGlasson self-assigned this Jul 1, 2024
@LiamGlasson
Copy link
Collaborator

This issue was unknowingly resolved in this commit. The problem was caused by the following behaviour in the old code:

  1. When question constraints weren't found, constraints_position was -1.
  2. This led to constraints_position + len(constraint_query_string) being a small positive number.
  3. The resulting slice operation meant that most of the question content was included in the constraints field, surpassing the Discord embed limit.

When this commit was later merged on May 24th 2024, this issue was fixed as questions no longer included constraints. This means that all questions now fall within the Discord embed character limit of 6000 characters, and this issue can be closed.

@Kevin-Roman
Copy link
Contributor Author

Reopening this issue as problem 1352 exceeds the embed limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants