From bbef4f27a5ebade439e7073f66cac20977b18472 Mon Sep 17 00:00:00 2001 From: Shom770 <82843611+Shom770@users.noreply.github.com> Date: Wed, 13 Oct 2021 18:53:34 -0400 Subject: fixing errors --- bot/exts/utilities/challenges.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'bot/exts/utilities/challenges.py') diff --git a/bot/exts/utilities/challenges.py b/bot/exts/utilities/challenges.py index 234eb0be..ff9394ce 100644 --- a/bot/exts/utilities/challenges.py +++ b/bot/exts/utilities/challenges.py @@ -162,10 +162,16 @@ class Challenges(commands.Cog): kata_description = "\n".join(kata_description[:1000].split("\n")[:-1]) + "..." kata_description += f" [continue reading]({kata_url})" + if kata_information["rank"]["name"] is None: + embed_color = 8 + kata_information["rank"]["name"] = "Unable to retrieve difficulty for beta languages." + else: + embed_color = int(kata_information["rank"]["name"].replace(" kyu", "")) + kata_embed = Embed( title=kata_information["name"], description=kata_description, - color=MAPPING_OF_KYU[int(kata_information["rank"]["name"].replace(" kyu", ""))], + color=MAPPING_OF_KYU[embed_color], url=kata_url ) kata_embed.add_field(name="Difficulty", value=kata_information["rank"]["name"], inline=False) @@ -275,8 +281,7 @@ class Challenges(commands.Cog): params = {} if language and not query: - level = f"-{choice([1, 2, 3, 4, 5, 6, 7, 8])}" - params["r[]"] = level + pass elif "," in query: query_splitted = query.split("," if ", " not in query else ", ") -- cgit v1.2.3 From 196c451c867bc78beab2492b963b7d9a1f6a13f5 Mon Sep 17 00:00:00 2001 From: Shom770 <82843611+Shom770@users.noreply.github.com> Date: Thu, 14 Oct 2021 06:37:27 -0400 Subject: requested changes from TizzySaurus implemented --- bot/exts/utilities/challenges.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'bot/exts/utilities/challenges.py') diff --git a/bot/exts/utilities/challenges.py b/bot/exts/utilities/challenges.py index ff9394ce..d3ef82a0 100644 --- a/bot/exts/utilities/challenges.py +++ b/bot/exts/utilities/challenges.py @@ -164,9 +164,10 @@ class Challenges(commands.Cog): if kata_information["rank"]["name"] is None: embed_color = 8 - kata_information["rank"]["name"] = "Unable to retrieve difficulty for beta languages." + kata_difficulty = "Unable to retrieve difficulty for beta languages." else: embed_color = int(kata_information["rank"]["name"].replace(" kyu", "")) + kata_difficulty = kata_information["rank"]["name"] kata_embed = Embed( title=kata_information["name"], @@ -174,7 +175,7 @@ class Challenges(commands.Cog): color=MAPPING_OF_KYU[embed_color], url=kata_url ) - kata_embed.add_field(name="Difficulty", value=kata_information["rank"]["name"], inline=False) + kata_embed.add_field(name="Difficulty", value=kata_difficulty, inline=False) return kata_embed @staticmethod @@ -280,9 +281,7 @@ class Challenges(commands.Cog): get_kata_link = f"https://codewars.com/kata/search/{language}" params = {} - if language and not query: - pass - elif "," in query: + if query is not None and "," in query: query_splitted = query.split("," if ", " not in query else ", ") if len(query_splitted) > 2: @@ -293,9 +292,9 @@ class Challenges(commands.Cog): query, level = query_splitted params["q"] = query params["r[]"] = f"-{level}" - elif query.isnumeric(): + elif query is not None and query.isnumeric(): params["r[]"] = f"-{query}" - else: + elif query is not None: params["q"] = query params["beta"] = str(language in SUPPORTED_LANGUAGES["beta"]).lower() -- cgit v1.2.3 From 3ff315f34721bca59b0820207da6bdd748155293 Mon Sep 17 00:00:00 2001 From: Shom770 <82843611+Shom770@users.noreply.github.com> Date: Thu, 14 Oct 2021 06:51:23 -0400 Subject: removed repeating query is None --- bot/exts/utilities/challenges.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'bot/exts/utilities/challenges.py') diff --git a/bot/exts/utilities/challenges.py b/bot/exts/utilities/challenges.py index d3ef82a0..e4738455 100644 --- a/bot/exts/utilities/challenges.py +++ b/bot/exts/utilities/challenges.py @@ -281,21 +281,22 @@ class Challenges(commands.Cog): get_kata_link = f"https://codewars.com/kata/search/{language}" params = {} - if query is not None and "," in query: - query_splitted = query.split("," if ", " not in query else ", ") - - if len(query_splitted) > 2: - raise commands.BadArgument( - "There can only be one comma within the query, separating the difficulty and the query itself." - ) - - query, level = query_splitted - params["q"] = query - params["r[]"] = f"-{level}" - elif query is not None and query.isnumeric(): - params["r[]"] = f"-{query}" - elif query is not None: - params["q"] = query + if query is not None: + if "," in query: + query_splitted = query.split("," if ", " not in query else ", ") + + if len(query_splitted) > 2: + raise commands.BadArgument( + "There can only be one comma within the query, separating the difficulty and the query itself." + ) + + query, level = query_splitted + params["q"] = query + params["r[]"] = f"-{level}" + elif query.isnumeric(): + params["r[]"] = f"-{query}" + else: + params["q"] = query params["beta"] = str(language in SUPPORTED_LANGUAGES["beta"]).lower() -- cgit v1.2.3 From a32fae52425fe6955be2be013f6149c90cc86e61 Mon Sep 17 00:00:00 2001 From: Shom770 <82843611+Shom770@users.noreply.github.com> Date: Sat, 6 Nov 2021 11:22:13 -0400 Subject: lowering challenges for compatibility with uppercase languages --- bot/exts/utilities/challenges.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/utilities/challenges.py') diff --git a/bot/exts/utilities/challenges.py b/bot/exts/utilities/challenges.py index e4738455..1f296390 100644 --- a/bot/exts/utilities/challenges.py +++ b/bot/exts/utilities/challenges.py @@ -278,7 +278,7 @@ class Challenges(commands.Cog): if language.lower() not in SUPPORTED_LANGUAGES["stable"] + SUPPORTED_LANGUAGES["beta"]: raise commands.BadArgument("This is not a recognized language on codewars.com!") - get_kata_link = f"https://codewars.com/kata/search/{language}" + get_kata_link = f"https://codewars.com/kata/search/{language.lower()}" params = {} if query is not None: -- cgit v1.2.3 From 7227fe279574ee0626ad6c7ead754c1212669af2 Mon Sep 17 00:00:00 2001 From: Shom770 <82843611+Shom770@users.noreply.github.com> Date: Sat, 6 Nov 2021 23:02:26 -0400 Subject: Change language to language.lower() --- bot/exts/utilities/challenges.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'bot/exts/utilities/challenges.py') diff --git a/bot/exts/utilities/challenges.py b/bot/exts/utilities/challenges.py index 1f296390..751ea2a3 100644 --- a/bot/exts/utilities/challenges.py +++ b/bot/exts/utilities/challenges.py @@ -275,10 +275,12 @@ class Challenges(commands.Cog): `.challenge , ` - Pulls a random challenge with the query provided, under that difficulty within the language's scope. """ - if language.lower() not in SUPPORTED_LANGUAGES["stable"] + SUPPORTED_LANGUAGES["beta"]: + + language = language.lower() + if language not in SUPPORTED_LANGUAGES["stable"] + SUPPORTED_LANGUAGES["beta"]: raise commands.BadArgument("This is not a recognized language on codewars.com!") - get_kata_link = f"https://codewars.com/kata/search/{language.lower()}" + get_kata_link = f"https://codewars.com/kata/search/{language}" params = {} if query is not None: -- cgit v1.2.3 From 1503845b4c5349e1a49c9c9ecdc37425b659e73b Mon Sep 17 00:00:00 2001 From: Shom770 <82843611+Shom770@users.noreply.github.com> Date: Sun, 7 Nov 2021 11:19:05 -0500 Subject: Fix line after function docstring --- bot/exts/utilities/challenges.py | 1 - 1 file changed, 1 deletion(-) (limited to 'bot/exts/utilities/challenges.py') diff --git a/bot/exts/utilities/challenges.py b/bot/exts/utilities/challenges.py index 751ea2a3..ab7ae442 100644 --- a/bot/exts/utilities/challenges.py +++ b/bot/exts/utilities/challenges.py @@ -275,7 +275,6 @@ class Challenges(commands.Cog): `.challenge , ` - Pulls a random challenge with the query provided, under that difficulty within the language's scope. """ - language = language.lower() if language not in SUPPORTED_LANGUAGES["stable"] + SUPPORTED_LANGUAGES["beta"]: raise commands.BadArgument("This is not a recognized language on codewars.com!") -- cgit v1.2.3