ZeLarpMaster / ZeCogsV3

My personal https://github.com/Twentysix26/Red-DiscordBot repo for V3 cogs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Birthdays] Message is over embed limit

aikaterna opened this issue · comments

Hey there, I have a server where a lot of people use the birthdays cog on my bot and I've reached an embed limit size for the [p]bday list command. I'm including the traceback below, sorry I was on an older version of birthdays so the line numbers don't match up to what's live, but I compared it to the current birthdays cog and the implementation for the output is the same.

Traceback (most recent call last):
  File "/.../cat38/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/.../Red-DiscordBot/cogs/CogManager/cogs/birthdays/birthdays.py", line 146, in bday_list
    await message.channel.send(embed=embed)
  File "/.../cat38/lib/python3.8/site-packages/discord/abc.py", line 890, in send
    data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
  File "/.../cat38/lib/python3.8/site-packages/discord/http.py", line 245, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed: Embed size exceeds maximum size of 6000

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/.../cat38/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "/.../cat38/lib/python3.8/site-packages/redbot/core/commands/commands.py", line 799, in invoke
    await super().invoke(ctx)
  File "/.../cat38/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1307, in invoke
    await ctx.invoked_subcommand.invoke(ctx)
  File "/.../cat38/lib/python3.8/site-packages/discord/ext/commands/core.py", line 855, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/.../cat38/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed: Embed size exceeds maximum size of 6000

In looking at this I found a couple different ways it could be changed, which I can PR if you'd like.

The first takes all of the months and birthdays and appends it to a string, which can get broken up across embeds breaking at a month break (with multiple months possible per 2000 char limit per embed), and outputting all pages. On this example server with a very long list, this equals out to 4 messages worth of embeds.

The other way this could be changed is a menu, where those 4 pages could be appended to a menu output but some folks I know don't care for menus much because then they'd either need to browse as a month per page, or a couple months per page, and the output left in the channel is a partial output (one page out of many), which might make people run the command more just trying to find their month or something.

One way that I didn't try to approach this is finding out combined length for fields and trying to arrange the fields paginated across embeds while breaking it appropriately before 6000 chars.

Attached is an example of the output I described above. If you'd like more pages I can show you but this was a rather long output so I didn't want to spam the issue.

example

Or feel free to just do your own thing, this is your cog after all 😺

I feared the day this cog would be used enough for this. I unfortunately don't spend much time on these cogs anymore so a PR would be greatly appreciated. Since these birthdays are inherently public, I think the best approach would be to send multiple messages back to back, put a cooldown on the command and suggest to the user to put the list in a public read-only channel in which they run the command every now and then to update it. Ideally should try to squeeze out as much birthdays in a single message as possible, but it's not necessary. This feels to me like the most future-proof way to do it, what do you think?

Do you have any preference on cooldown time? I'd guess something like 1 per channel every 10 sec, that way it's not really truly spammable without a bit of effort from the attempted-spammy user, but whatever you feel is alright here would be ok with me.

iirc the ratelimit for sending messages is around 4 messages per 5 seconds, so 10 seconds means we get another problem at only 8 pages. I think one minute isn't too much for something like this and gives us a bit more room to play with

Sounds good. I'll send you a PR a bit later to see if you like it.