aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/utilities/realpython.py
diff options
context:
space:
mode:
authorGravatar TizzySaurus <[email protected]>2021-11-29 09:15:05 +0000
committerGravatar GitHub <[email protected]>2021-11-29 09:15:05 +0000
commitc462d899f02495a4875df1f59fd97b39202ba8de (patch)
treed6a60f9735ae21c7ef5d546ec2cfc8c84b1200c2 /bot/exts/utilities/realpython.py
parentChange `MODERATION_ROLES` and `STAFF_ROLES` constants to be a set (diff)
parentMerge pull request #951 from python-discord/file_logging (diff)
Merge branch 'main' into update-role-constants
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(