diff options
| author | 2021-11-14 16:55:34 +0100 | |
|---|---|---|
| committer | 2021-11-14 16:55:34 +0100 | |
| commit | 8c2da5a0f80af4458a36cb3977d449c0cc5e039f (patch) | |
| tree | e931381b6551e6e6309c21f816b9f694cf24ecd6 /bot/exts/utilities/realpython.py | |
| parent | Resources: add copyright notice to ryanzec_colours.json (diff) | |
| parent | Merge pull request #943 from python-discord/file-log-debug (diff) | |
Merge branch 'main' into color-677
Diffstat (limited to 'bot/exts/utilities/realpython.py')
| -rw-r--r-- | bot/exts/utilities/realpython.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/bot/exts/utilities/realpython.py b/bot/exts/utilities/realpython.py index ef8b2638..bf8f1341 100644 --- a/bot/exts/utilities/realpython.py +++ b/bot/exts/utilities/realpython.py @@ -1,5 +1,6 @@ import logging from html import unescape +from typing import Optional from urllib.parse import quote_plus from discord import Embed @@ -31,9 +32,18 @@ class RealPython(commands.Cog): @commands.command(aliases=["rp"]) @commands.cooldown(1, 10, commands.cooldowns.BucketType.user) - async def realpython(self, ctx: commands.Context, *, user_search: str) -> None: - """Send 5 articles that match the user's search terms.""" - params = {"q": user_search, "limit": 5, "kind": "article"} + async def realpython(self, ctx: commands.Context, amount: Optional[int] = 5, *, user_search: str) -> None: + """ + Send some articles from RealPython that match the search terms. + + By default the top 5 matches are sent, this can be overwritten to + a number between 1 and 5 by specifying an amount before the search query. + """ + if not 1 <= amount <= 5: + await ctx.send("`amount` must be between 1 and 5 (inclusive).") + return + + params = {"q": user_search, "limit": amount, "kind": "article"} async with self.bot.http_session.get(url=API_ROOT, params=params) as response: if response.status != 200: logger.error( |