aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2021-11-11 16:46:31 -0800
committerGravatar GitHub <[email protected]>2021-11-11 16:46:31 -0800
commit8b0c2b55aff4ee21d52e9a8d44ffeec701767d76 (patch)
tree3e6fa933f0bb0cc7ca912c369224b9e006e12cb4
parentremove unnecessary volumes (diff)
parentMerge PR #909: Fix challenge cog not working for beta languages (diff)
Merge branch 'main' into coloredlogs
-rw-r--r--bot/exts/utilities/challenges.py44
1 files changed, 25 insertions, 19 deletions
diff --git a/bot/exts/utilities/challenges.py b/bot/exts/utilities/challenges.py
index 234eb0be..ab7ae442 100644
--- a/bot/exts/utilities/challenges.py
+++ b/bot/exts/utilities/challenges.py
@@ -162,13 +162,20 @@ 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_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"],
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)
+ kata_embed.add_field(name="Difficulty", value=kata_difficulty, inline=False)
return kata_embed
@staticmethod
@@ -268,30 +275,29 @@ class Challenges(commands.Cog):
`.challenge <language> <query>, <difficulty>` - 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}"
params = {}
- if language and not query:
- level = f"-{choice([1, 2, 3, 4, 5, 6, 7, 8])}"
- params["r[]"] = level
- elif "," in query:
- query_splitted = query.split("," if ", " not in query else ", ")
+ 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."
- )
+ 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
+ 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()