diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/info/pypi.py | 35 | 
1 files changed, 35 insertions, 0 deletions
| diff --git a/bot/exts/info/pypi.py b/bot/exts/info/pypi.py new file mode 100644 index 000000000..9567516c2 --- /dev/null +++ b/bot/exts/info/pypi.py @@ -0,0 +1,35 @@ +from discord import Embed +from discord.ext.commands import Cog, Context, command + +from bot.bot import Bot +from bot.constants import NEGATIVE_REPLIES + +URL = "https://pypi.org/pypi/{package}/json" + + +class PyPi(Cog): +    """Cog for getting information about PyPi packages.""" + +    def __init__(self, bot: Bot): +        self.bot = bot + +    @command(name="pypi", aliases=("package", "pack")) +    async def get_package_info(self, ctx: Context, package: str) -> None: +        """Getting information about a specific package.""" +        embed = Embed(title="PyPi package information") + +        async with self.bot.http_session.get(URL.format(package_name=package)) as response: +            if response.status == 404: +                return await ctx.send(f"Package with name '{package}' could not be found.") +            elif response.status == 200 and response.content_type == "application/json": +                response_json = await response.json() +                info = response_json["info"] +            else: +                return await ctx.send("There was an error when fetching your PyPi package.") + +        await ctx.send(embed=embed) + + +def setup(bot: Bot) -> None: +    """Load the PyPi cog.""" +    bot.add_cog(PyPi(bot)) | 
