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

Add an explicit character limit to system/member descriptions #14

Closed
xSke opened this issue Sep 7, 2018 · 2 comments
Closed

Add an explicit character limit to system/member descriptions #14

xSke opened this issue Sep 7, 2018 · 2 comments

Comments

@xSke
Copy link
Member

xSke commented Sep 7, 2018

Embeds break past 1024 characters per field, so if you try to set a description past that (up to 2000, which is the command message limit), it'll silently break posting the card.

@Ryonez
Copy link
Contributor

Ryonez commented Sep 7, 2018

A paginator could potentially help, maybe something like this:

def pagify(text, delims=["\n"], *, escape=True, shorten_by=8,
           page_length=2000):
    """DOES NOT RESPECT MARKDOWN BOXES OR INLINE CODE"""
    in_text = text
    if escape:
        num_mentions = text.count("@here") + text.count("@everyone")
        shorten_by += num_mentions
    page_length -= shorten_by
    while len(in_text) > page_length:
        closest_delim = max([in_text.rfind(d, 0, page_length)
                             for d in delims])
        closest_delim = closest_delim if closest_delim != -1 else page_length
        if escape:
            to_send = escape_mass_mentions(in_text[:closest_delim])
        else:
            to_send = in_text[:closest_delim]
        yield to_send
        in_text = in_text[closest_delim:]

    if escape:
        yield escape_mass_mentions(in_text)
    else:
        yield in_text

A little something found from Red: https://github.com/Cog-Creators/Red-DiscordBot/blob/develop/cogs/utils/chat_formatting.py

Note, there's a limit of 20 fields to an embed and while the field character limit is 1024, the descriptions limit is 2048.

@xSke
Copy link
Member Author

xSke commented Sep 7, 2018

I'd rather cap it than deal with complex pagination stuff, honestly. 1024 should be enough.

@xSke xSke closed this as completed in 5930f49 Sep 7, 2018
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

No branches or pull requests

2 participants