From 475bd2124d56f6a59933b79b2f22c2b6c8896a25 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 14 Apr 2021 00:19:25 +0100 Subject: 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. --- bot/exts/utils/utils.py | 27 ++++++++++++++++++--------- 1 file 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) -- cgit v1.2.3 From f9fb8631ce8568e0c9f15ea4ff0977e722ede3ba Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 14 Apr 2021 10:23:38 +0100 Subject: Require at least one snowflake to be provided. --- bot/exts/utils/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bot/exts/utils/utils.py b/bot/exts/utils/utils.py index 60383996d..0fe0cab78 100644 --- a/bot/exts/utils/utils.py +++ b/bot/exts/utils/utils.py @@ -162,6 +162,9 @@ 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.") + if not snowflakes: + raise BadArgument("At least one snowflake must be provided.") + embed = Embed( colour=Colour.blue() ) -- cgit v1.2.3 From 56ff78ae70986dfbc01878e666a6aaf753739668 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 14 Apr 2021 17:48:49 +0100 Subject: Refactor embed to use just one line --- bot/exts/utils/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bot/exts/utils/utils.py b/bot/exts/utils/utils.py index 0fe0cab78..8d9d27c64 100644 --- a/bot/exts/utils/utils.py +++ b/bot/exts/utils/utils.py @@ -165,9 +165,7 @@ class Utils(Cog): if not snowflakes: raise BadArgument("At least one snowflake must be provided.") - embed = Embed( - colour=Colour.blue() - ) + 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" -- cgit v1.2.3