diff options
-rw-r--r-- | Pipfile | 2 | ||||
-rw-r--r-- | Pipfile.lock | 5 | ||||
-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 |
5 files changed, 15 insertions, 27 deletions
@@ -4,7 +4,7 @@ verify_ssl = true name = "pypi" [packages] -discord-py = {ref = "rewrite",git = "https://github.com/Rapptz/discord.py"} +discord-py = {ref = "3f06f24",git = "https://github.com/Rapptz/discord.py"} arrow = "*" beautifulsoup4 = "*" aiodns = "*" diff --git a/Pipfile.lock b/Pipfile.lock index e67f3d5b..1d078621 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "27243f1b58b38c7b873bcac661af6454eed41c7a7da9c812546fe3a98ed29949" + "sha256": "1b41990a905b26b2dfc8d59f3de837b4dffc0485d83e865bd9d9792276bb9b9c" }, "pipfile-spec": 6, "requires": { @@ -76,7 +76,7 @@ }, "discord-py": { "git": "https://github.com/Rapptz/discord.py", - "ref": "45af9fa40bc0083de3a695795029d6f6a85ce0d8" + "ref": "3f06f247c039a23948e7bb0014ea31db533b4ba2" }, "fuzzywuzzy": { "hashes": [ @@ -142,7 +142,6 @@ }, "pycparser": { "hashes": [ - "sha256:25043a2570be3ee8741c8f63eaad1602b7eced44a2586650756d765680a47898", "sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3" ], "version": "==2.19" @@ -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) |