diff options
Diffstat (limited to 'bot')
-rw-r--r-- | bot/bot.py | 2 | ||||
-rw-r--r-- | bot/seasons/evergreen/snakes/snakes_cog.py | 29 | ||||
-rw-r--r-- | bot/seasons/evergreen/snakes/utils.py | 4 |
3 files changed, 12 insertions, 23 deletions
@@ -68,4 +68,4 @@ class SeasonalBot(Bot): if isinstance(exception, commands.UserInputError): context.command.reset_cooldown(context) else: - super().on_command_error(context, exception) + await super().on_command_error(context, exception) diff --git a/bot/seasons/evergreen/snakes/snakes_cog.py b/bot/seasons/evergreen/snakes/snakes_cog.py index f2f63141..4ed277bd 100644 --- a/bot/seasons/evergreen/snakes/snakes_cog.py +++ b/bot/seasons/evergreen/snakes/snakes_cog.py @@ -148,7 +148,10 @@ class Snakes: def __init__(self, bot: Bot): self.active_sal = {} self.bot = bot - # self.headers = {"X-API-KEY": Keys.site_api} + self.snake_names = utils.get_resource("snake_names") + self.snake_idioms = utils.get_resource("snake_idioms") + self.snake_quizzes = utils.get_resource("snake_quiz") + self.snake_facts = utils.get_resource("snake_facts") # region: Helper methods @staticmethod @@ -417,7 +420,7 @@ class Snakes: Gets a random snake name. :return: A random snake name, as a string. """ - return await utils.get_resource("snake_names") + return random.choice(self.snake_names) async def _validate_answer(self, ctx: Context, message: Message, answer: str, options: list): """ @@ -628,21 +631,15 @@ class Snakes: random.randint(50, 70), ) - # Get a snake idiom from the API - # response = await self.bot.http_session.get(URLs.site_idioms_api, headers=self.headers) - # text = await response.json() - # TODO: did the API return a random name or something?? - # why was text being passed as-is without str conversion? - text = await utils.get_resource("snake_idioms") - # Build and send the snek + text = random.choice(self.snake_idioms)["idiom"] factory = utils.PerlinNoiseFactory(dimension=1, octaves=2) image_frame = utils.create_snek_frame( factory, snake_width=width, snake_length=length, snake_color=snek_color, - text=str(text), + text=text, text_color=text_color, bg_color=bg_color ) @@ -848,10 +845,7 @@ class Snakes: """ # Prepare a question. - # response = await self.bot.http_session.get(URLs.site_quiz_api, headers=self.headers) - # question = await response.json() - question = await utils.get_resource("snake_quiz") - + question = random.choice(self.snake_quizzes) answer = question["answerkey"] options = {key: question["options"][key] for key in ANSWERS_EMOJI.keys()} @@ -1052,12 +1046,7 @@ class Snakes: Modified by lemon. """ - # Get a fact from the API. - # response = await self.bot.http_session.get(URLs.site_facts_api, headers=self.headers) - # question = await response.json() - question = await utils.get_resource("snake_facts") - - # Build and send the embed. + question = random.choice(self.snake_facts)["fact"] embed = Embed( title="Snake fact", color=SNAKE_COLOR, diff --git a/bot/seasons/evergreen/snakes/utils.py b/bot/seasons/evergreen/snakes/utils.py index 1e2ccacd..9823d701 100644 --- a/bot/seasons/evergreen/snakes/utils.py +++ b/bot/seasons/evergreen/snakes/utils.py @@ -11,7 +11,7 @@ import math import random from itertools import product from pathlib import Path -from typing import Dict, Tuple +from typing import List, Tuple import aiohttp from PIL import Image @@ -114,7 +114,7 @@ Y = 1 ANGLE_RANGE = math.pi * 2 -async def get_resource(file: str) -> Dict[str, str]: +def get_resource(file: str) -> List[dict]: with (SNAKE_RESOURCES / f"{file}.json").open() as snakefile: return json.load(snakefile) |