From c245348a8992665d132178627397b1b2a95f9314 Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Fri, 17 Jun 2022 00:52:48 -0700 Subject: RealPython home page displayed on no user search. (#1063) --- bot/exts/utilities/realpython.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'bot/exts/utilities/realpython.py') diff --git a/bot/exts/utilities/realpython.py b/bot/exts/utilities/realpython.py index bf8f1341..5e9757d0 100644 --- a/bot/exts/utilities/realpython.py +++ b/bot/exts/utilities/realpython.py @@ -11,11 +11,10 @@ from bot.constants import Colours logger = logging.getLogger(__name__) - API_ROOT = "https://realpython.com/search/api/v1/" ARTICLE_URL = "https://realpython.com{article_url}" SEARCH_URL = "https://realpython.com/search?q={user_search}" - +HOME_URL = "https://realpython.com/" ERROR_EMBED = Embed( title="Error while searching Real Python", @@ -32,13 +31,22 @@ class RealPython(commands.Cog): @commands.command(aliases=["rp"]) @commands.cooldown(1, 10, commands.cooldowns.BucketType.user) - async def realpython(self, ctx: commands.Context, amount: Optional[int] = 5, *, user_search: str) -> None: + async def realpython(self, ctx: commands.Context, amount: Optional[int] = 5, *, + user_search: Optional[str] = None) -> None: """ Send some articles from RealPython that match the search terms. - By default the top 5 matches are sent, this can be overwritten to + 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 no search query is specified by the user, the home page is sent. """ + if user_search is None: + home_page_embed = Embed(title="Real Python Home Page", url=HOME_URL, colour=Colours.orange) + + await ctx.send(embed=home_page_embed) + + return + if not 1 <= amount <= 5: await ctx.send("`amount` must be between 1 and 5 (inclusive).") return -- cgit v1.2.3