aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/utilities/realpython.py
diff options
context:
space:
mode:
authorGravatar NipaDev <[email protected]>2021-11-05 03:18:11 +0200
committerGravatar GitHub <[email protected]>2021-11-05 01:18:11 +0000
commit2cd5aa83a722f4137e32514dfe9c45688be365ac (patch)
tree19fd4ab6f655d288ddf31dddb592a90cea956395 /bot/exts/utilities/realpython.py
parentMerge pull request #935 from SavagePastaMan/remove-skill-level-topic (diff)
Add option to get specific amount of realpython articles
Add a feature to choice in between 1-5 (inclusive) articles. If value not specified, the default, 5 will be used. Co-authored-by: ChrisJL <[email protected]>
Diffstat (limited to 'bot/exts/utilities/realpython.py')
-rw-r--r--bot/exts/utilities/realpython.py16
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(