diff options
| author | 2021-03-12 11:39:12 -0800 | |
|---|---|---|
| committer | 2021-03-12 13:14:04 -0800 | |
| commit | 1b1e7adaca4b116a69db06955ab2a3edb222ef52 (patch) | |
| tree | 1416afb5397f59b97ccbb3f77fe75459f309d79f | |
| parent | Merge pull request #1455 from python-discord/many-snowflakes (diff) | |
Added '_' to allowed chars, shortened embed.
| -rw-r--r-- | bot/exts/info/pypi.py | 33 | 
1 files changed, 12 insertions, 21 deletions
| diff --git a/bot/exts/info/pypi.py b/bot/exts/info/pypi.py index 10029aa73..2e42e7d6b 100644 --- a/bot/exts/info/pypi.py +++ b/bot/exts/info/pypi.py @@ -11,12 +11,11 @@ from bot.bot import Bot  from bot.constants import Colours, NEGATIVE_REPLIES, RedirectOutput  URL = "https://pypi.org/pypi/{package}/json" -FIELDS = ("author", "requires_python", "summary", "license")  PYPI_ICON = "https://cdn.discordapp.com/emojis/766274397257334814.png"  PYPI_COLOURS = itertools.cycle((Colours.yellow, Colours.blue, Colours.white)) -ILLEGAL_CHARACTERS = re.compile(r"[^a-zA-Z0-9-.]+") +ILLEGAL_CHARACTERS = re.compile(r"[^-_.a-zA-Z0-9]+")  INVALID_INPUT_DELETE_DELAY = RedirectOutput.delete_delay  log = logging.getLogger(__name__) @@ -31,16 +30,13 @@ class PyPi(Cog):      @command(name="pypi", aliases=("package", "pack"))      async def get_package_info(self, ctx: Context, package: str) -> None:          """Provide information about a specific package from PyPI.""" -        embed = Embed( -            title=random.choice(NEGATIVE_REPLIES), -            colour=Colours.soft_red -        ) +        embed = Embed(title=random.choice(NEGATIVE_REPLIES), colour=Colours.soft_red)          embed.set_thumbnail(url=PYPI_ICON)          error = True -        if (character := re.search(ILLEGAL_CHARACTERS, package)) is not None: -            embed.description = f"Illegal character passed into command: '{escape_markdown(character.group(0))}'" +        if characters := re.search(ILLEGAL_CHARACTERS, package): +            embed.description = f"Illegal character(s) passed into command: '{escape_markdown(characters.group(0))}'"          else:              async with self.bot.http_session.get(URL.format(package=package)) as response: @@ -52,22 +48,17 @@ class PyPi(Cog):                      info = response_json["info"]                      embed.title = f"{info['name']} v{info['version']}" -                    embed.url = info['package_url'] -                    embed.colour = next(PYPI_COLOURS) -                    for field in FIELDS: -                        field_data = info[field] +                    embed.url = info["package_url"] +                    embed.colour = next(PYPI_COLOURS) -                        # Field could be completely empty, in some cases can be a string with whitespaces, or None. -                        if field_data and not field_data.isspace(): -                            if '\n' in field_data and field == "license": -                                field_data = field_data.split('\n')[0] +                    summary = escape_markdown(info["summary"]) -                            embed.add_field( -                                name=field.replace("_", " ").title(), -                                value=escape_markdown(field_data), -                                inline=False, -                            ) +                    # Summary could be completely empty, or just whitespace. +                    if summary and not summary.isspace(): +                        embed.description = summary +                    else: +                        embed.description = "No summary provided."                      error = False | 
