From ded89e843980902e03e60a3a44997b91826300de Mon Sep 17 00:00:00 2001 From: "Karlis. S" Date: Sat, 29 Feb 2020 20:23:03 +0200 Subject: [PATCH 1/6] !roles Command: Added pagination (LinePaginator), moved roles amount to title (was before in footer). --- bot/cogs/information.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bot/cogs/information.py b/bot/cogs/information.py index 49beca15b9..4dd4a7e75d 100644 --- a/bot/cogs/information.py +++ b/bot/cogs/information.py @@ -13,6 +13,7 @@ from bot import constants from bot.bot import Bot from bot.decorators import InChannelCheckFailure, in_channel, with_role +from bot.pagination import LinePaginator from bot.utils.checks import cooldown_with_role_bypass, with_role_check from bot.utils.time import time_since @@ -32,20 +33,18 @@ async def roles_info(self, ctx: Context) -> None: # Sort the roles alphabetically and remove the @everyone role roles = sorted(ctx.guild.roles[1:], key=lambda role: role.name) - # Build a string - role_string = "" + # Build a list + role_list = [] for role in roles: - role_string += f"`{role.id}` - {role.mention}\n" + role_list.append(f"`{role.id}` - {role.mention}") # Build an embed embed = Embed( - title="Role information", - colour=Colour.blurple(), - description=role_string + title=f"Role information (Total {len(roles)} roles)", + colour=Colour.blurple() ) - embed.set_footer(text=f"Total roles: {len(roles)}") - await ctx.send(embed=embed) + await LinePaginator.paginate(role_list, ctx, embed) @with_role(*constants.MODERATION_ROLES) @command(name="role") From fc2224fc047fbbefdc17e3624ebc2854342c59c1 Mon Sep 17 00:00:00 2001 From: "Karlis. S" Date: Sun, 1 Mar 2020 09:35:34 +0200 Subject: [PATCH 2/6] !roles Command Test: Applied !roles command changes --- tests/bot/cogs/test_information.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/bot/cogs/test_information.py b/tests/bot/cogs/test_information.py index 8443cfe715..bb4ebd9d09 100644 --- a/tests/bot/cogs/test_information.py +++ b/tests/bot/cogs/test_information.py @@ -45,10 +45,9 @@ def test_roles_command_command(self): _, kwargs = self.ctx.send.call_args embed = kwargs.pop('embed') - self.assertEqual(embed.title, "Role information") + self.assertEqual(embed.title, "Role information (Total 1 roles)") self.assertEqual(embed.colour, discord.Colour.blurple()) - self.assertEqual(embed.description, f"`{self.moderator_role.id}` - {self.moderator_role.mention}\n") - self.assertEqual(embed.footer.text, "Total roles: 1") + self.assertEqual(embed.description, f"\n`{self.moderator_role.id}` - {self.moderator_role.mention}\n\n") def test_role_info_command(self): """Tests the `role info` command.""" From 25369cb35930b939eaf29d49cbf9fcce327607f2 Mon Sep 17 00:00:00 2001 From: ks123 Date: Thu, 5 Mar 2020 09:00:18 +0200 Subject: [PATCH 3/6] (Information Cog, !roles command): Added empty parameter to pagination (False) --- bot/cogs/information.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/information.py b/bot/cogs/information.py index 4dd4a7e75d..807c2264db 100644 --- a/bot/cogs/information.py +++ b/bot/cogs/information.py @@ -44,7 +44,7 @@ async def roles_info(self, ctx: Context) -> None: colour=Colour.blurple() ) - await LinePaginator.paginate(role_list, ctx, embed) + await LinePaginator.paginate(role_list, ctx, embed, empty=False) @with_role(*constants.MODERATION_ROLES) @command(name="role") From 5579f2d32d5faadad778d64c50cf6fbefccf4f28 Mon Sep 17 00:00:00 2001 From: ks123 Date: Thu, 5 Mar 2020 09:05:06 +0200 Subject: [PATCH 4/6] (Information Cog, !roles command test): Applied empty parameter change. --- tests/bot/cogs/test_information.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bot/cogs/test_information.py b/tests/bot/cogs/test_information.py index c6fd937b81..7c265bba82 100644 --- a/tests/bot/cogs/test_information.py +++ b/tests/bot/cogs/test_information.py @@ -47,7 +47,7 @@ def test_roles_command_command(self): self.assertEqual(embed.title, "Role information (Total 1 roles)") self.assertEqual(embed.colour, discord.Colour.blurple()) - self.assertEqual(embed.description, f"\n`{self.moderator_role.id}` - {self.moderator_role.mention}\n\n") + self.assertEqual(embed.description, f"\n`{self.moderator_role.id}` - {self.moderator_role.mention}\n") def test_role_info_command(self): """Tests the `role info` command.""" From 028d47821293b6004a7322bdbee28b5a484dd673 Mon Sep 17 00:00:00 2001 From: ks123 Date: Thu, 5 Mar 2020 09:07:02 +0200 Subject: [PATCH 5/6] (Information Cog, !roles command): Added 's' to end of 'role' only if there is more then 1 role. --- bot/cogs/information.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/information.py b/bot/cogs/information.py index 807c2264db..7921a49324 100644 --- a/bot/cogs/information.py +++ b/bot/cogs/information.py @@ -40,7 +40,7 @@ async def roles_info(self, ctx: Context) -> None: # Build an embed embed = Embed( - title=f"Role information (Total {len(roles)} roles)", + title=f"Role information (Total {len(roles)} role{'s' * (len(role_list) > 1)})", colour=Colour.blurple() ) From 0b75d3f5e717f99f53522d4224abea6223ef6c84 Mon Sep 17 00:00:00 2001 From: ks123 Date: Thu, 5 Mar 2020 09:08:10 +0200 Subject: [PATCH 6/6] (Information Cog, !roles command test): Removed 's' at end of "Total 1 role(s)" due changes in command. --- tests/bot/cogs/test_information.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bot/cogs/test_information.py b/tests/bot/cogs/test_information.py index 7c265bba82..3c26374f56 100644 --- a/tests/bot/cogs/test_information.py +++ b/tests/bot/cogs/test_information.py @@ -45,7 +45,7 @@ def test_roles_command_command(self): _, kwargs = self.ctx.send.call_args embed = kwargs.pop('embed') - self.assertEqual(embed.title, "Role information (Total 1 roles)") + self.assertEqual(embed.title, "Role information (Total 1 role)") self.assertEqual(embed.colour, discord.Colour.blurple()) self.assertEqual(embed.description, f"\n`{self.moderator_role.id}` - {self.moderator_role.mention}\n")