diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/converters.py | 44 | 
1 files changed, 5 insertions, 39 deletions
| diff --git a/bot/converters.py b/bot/converters.py index 0984fa0a3..559e759e1 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -18,6 +18,7 @@ from bot.api import ResponseCodeError  from bot.constants import URLs  from bot.errors import InvalidInfraction  from bot.exts.info.doc import _inventory_parser +from bot.exts.info.tags import TagIdentifier  from bot.log import get_logger  from bot.utils.extensions import EXTENSIONS, unqualify  from bot.utils.regex import INVITE_RE @@ -286,41 +287,6 @@ class Snowflake(IDConverter):          return snowflake -class TagNameConverter(Converter): -    """ -    Ensure that a proposed tag name is valid. - -    Valid tag names meet the following conditions: -        * All ASCII characters -        * Has at least one non-whitespace character -        * Not solely numeric -        * Shorter than 127 characters -    """ - -    @staticmethod -    async def convert(ctx: Context, tag_name: str) -> str: -        """Lowercase & strip whitespace from proposed tag_name & ensure it's valid.""" -        tag_name = tag_name.lower().strip() - -        # The tag name has at least one invalid character. -        if ascii(tag_name)[1:-1] != tag_name: -            raise BadArgument("Don't be ridiculous, you can't use that character!") - -        # The tag name is either empty, or consists of nothing but whitespace. -        elif not tag_name: -            raise BadArgument("Tag names should not be empty, or filled with whitespace.") - -        # The tag name is longer than 127 characters. -        elif len(tag_name) > 127: -            raise BadArgument("Are you insane? That's way too long!") - -        # The tag name is ascii but does not contain any letters. -        elif not any(character.isalpha() for character in tag_name): -            raise BadArgument("Tag names must contain at least one letter.") - -        return tag_name - -  class SourceConverter(Converter):      """Convert an argument into a help command, tag, command, or cog.""" @@ -343,9 +309,10 @@ class SourceConverter(Converter):          if not tags_cog:              show_tag = False -        elif argument.lower() in tags_cog._cache: -            return argument.lower() - +        else: +            identifier = TagIdentifier.from_string(argument.lower()) +            if identifier in tags_cog.tags: +                return identifier          escaped_arg = escape_markdown(argument)          raise BadArgument( @@ -615,7 +582,6 @@ if t.TYPE_CHECKING:      ValidURL = str  # noqa: F811      Inventory = t.Tuple[str, _inventory_parser.InventoryDict]  # noqa: F811      Snowflake = int  # noqa: F811 -    TagNameConverter = str  # noqa: F811      SourceConverter = SourceType  # noqa: F811      DurationDelta = relativedelta  # noqa: F811      Duration = datetime  # noqa: F811 | 
