diff options
| author | 2021-04-14 00:19:25 +0100 | |
|---|---|---|
| committer | 2021-04-14 00:19:25 +0100 | |
| commit | 475bd2124d56f6a59933b79b2f22c2b6c8896a25 (patch) | |
| tree | 8262586343cfd5ab17fb08c0e5da62db760a12fb | |
| parent | Merge pull request #1521 from ToxicKidz/dont-use-startswith (diff) | |
Use a paginated embed to output multiple snowflakes
Previously each snowflake passed to the command would have their own embed, which may cause
the bot to send many embeds if a staff unknowingly passed it a bunch of snowflakes. This change
makes sure that we don't run into rate limits on the bot by sending all of the snowflakes in one embed.
| -rw-r--r-- | bot/exts/utils/utils.py | 27 | 
1 files changed, 18 insertions, 9 deletions
| diff --git a/bot/exts/utils/utils.py b/bot/exts/utils/utils.py index cae7f2593..60383996d 100644 --- a/bot/exts/utils/utils.py +++ b/bot/exts/utils/utils.py @@ -162,17 +162,26 @@ class Utils(Cog):          if len(snowflakes) > 1 and await has_no_roles_check(ctx, *STAFF_ROLES):              raise BadArgument("Cannot process more than one snowflake in one invocation.") +        embed = Embed( +            colour=Colour.blue() +        ) +        embed.set_author( +            name=f"Snowflake{'s'[:len(snowflakes)^1]}",  # Deals with pluralisation +            icon_url="https://github.com/twitter/twemoji/blob/master/assets/72x72/2744.png?raw=true" +        ) + +        lines = []          for snowflake in snowflakes:              created_at = snowflake_time(snowflake) -            embed = Embed( -                description=f"**Created at {created_at}** ({time_since(created_at, max_units=3)}).", -                colour=Colour.blue() -            ) -            embed.set_author( -                name=f"Snowflake: {snowflake}", -                icon_url="https://github.com/twitter/twemoji/blob/master/assets/72x72/2744.png?raw=true" -            ) -            await ctx.send(embed=embed) +            lines.append(f"**{snowflake}**\nCreated at {created_at} ({time_since(created_at, max_units=3)}).") + +        await LinePaginator.paginate( +            lines, +            ctx=ctx, +            embed=embed, +            max_lines=5, +            max_size=1000 +        )      @command(aliases=("poll",))      @has_any_role(*MODERATION_ROLES, Roles.project_leads, Roles.domain_leads) | 
