Skip to content

Commit

Permalink
Merge pull request python-discord#807 from ks129/roles-command-pagina…
Browse files Browse the repository at this point in the history
…tion

Added Pagination to !roles command
  • Loading branch information
scragly authored Mar 5, 2020
2 parents b63b854 + 90aa9d3 commit 5c0cef2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
15 changes: 7 additions & 8 deletions bot/cogs/information.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)} role{'s' * (len(role_list) > 1)})",
colour=Colour.blurple()
)
embed.set_footer(text=f"Total roles: {len(roles)}")

await ctx.send(embed=embed)
await LinePaginator.paginate(role_list, ctx, embed, empty=False)

@with_role(*constants.MODERATION_ROLES)
@command(name="role")
Expand Down
5 changes: 2 additions & 3 deletions tests/bot/cogs/test_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 role)")
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")

def test_role_info_command(self):
"""Tests the `role info` command."""
Expand Down

0 comments on commit 5c0cef2

Please sign in to comment.