diff options
| author | 2019-10-01 16:13:30 +0100 | |
|---|---|---|
| committer | 2019-10-01 16:13:30 +0100 | |
| commit | ccd03e48896eaca98add143538221cbd671aef4f (patch) | |
| tree | 29917e22f8059930f9f8be4576455978b8e47e15 | |
| parent | Add unit tests for role info command (diff) | |
Implement review comments and stop using a greedy converter
Diffstat (limited to '')
| -rw-r--r-- | bot/cogs/information.py | 26 | 
1 files changed, 22 insertions, 4 deletions
| diff --git a/bot/cogs/information.py b/bot/cogs/information.py index 2dd56333f..624097eb1 100644 --- a/bot/cogs/information.py +++ b/bot/cogs/information.py @@ -1,9 +1,10 @@  import colorsys  import logging  import textwrap +import typing -from discord import CategoryChannel, Colour, Embed, Member, Role, TextChannel, VoiceChannel -from discord.ext.commands import Bot, Cog, Context, Greedy, command +from discord import CategoryChannel, Colour, Embed, Member, Role, TextChannel, VoiceChannel, utils +from discord.ext.commands import Bot, Cog, Context, command  from bot.constants import Channels, Emojis, MODERATION_ROLES, STAFF_ROLES  from bot.decorators import InChannelCheckFailure, with_role @@ -53,13 +54,30 @@ class Information(Cog):      @with_role(*MODERATION_ROLES)      @command(name="role") -    async def role_info(self, ctx: Context, roles: Greedy[Role]): +    async def role_info(self, ctx: Context, *roles: typing.Union[Role, str]):          """          Return information on a role or list of roles.          To specify multiple roles just add to the arguments, delimit roles with spaces in them using quotation marks.          """ -        for role in roles: +        parsed_roles = [] + +        for role_name in roles: +            if isinstance(role_name, Role): +                # Role conversion has already succeeded +                parsed_roles.append(role_name) +                continue + +            role = utils.find(lambda r: r.name.lower() == role_name.lower(), ctx.guild.roles) + +            if not role: +                await ctx.send(f":x: Could not convert `{role_name}` to a role") +                continue + +            parsed_roles.append(role) +             + +        for role in parsed_roles:              embed = Embed(                  title=f"{role.name} info",                  colour=role.colour, | 
