diff options
| author | 2021-05-15 13:31:34 -0400 | |
|---|---|---|
| committer | 2021-05-15 13:31:34 -0400 | |
| commit | f8a179df350eb3abb7f3595aaff3dbca312f540c (patch) | |
| tree | 6868ae98b81b614f8d8d68f1a9bbc06c7cb94490 /bot/exts/easter | |
| parent | chore: Make all aliases in commands tuples (diff) | |
chore: Make things that are only used once constants
Diffstat (limited to 'bot/exts/easter')
| -rw-r--r-- | bot/exts/easter/earth_photos.py | 4 | ||||
| -rw-r--r-- | bot/exts/easter/egg_facts.py | 12 |
2 files changed, 6 insertions, 10 deletions
diff --git a/bot/exts/easter/earth_photos.py b/bot/exts/easter/earth_photos.py index 9df4f9ca..f65790af 100644 --- a/bot/exts/easter/earth_photos.py +++ b/bot/exts/easter/earth_photos.py @@ -9,6 +9,8 @@ from bot.constants import Tokens log = logging.getLogger(__name__) +API_URL = "https://api.unsplash.com/photos/random" + class EarthPhotos(commands.Cog): """This cog contains the command for earth photos.""" @@ -21,7 +23,7 @@ class EarthPhotos(commands.Cog): """Returns a random photo of earth, sourced from Unsplash.""" async with ctx.typing(): async with self.bot.http_session.get( - "https://api.unsplash.com/photos/random", + API_URL, params={"query": "planet_earth", "client_id": Tokens.unsplash_access_key} ) as r: jsondata = await r.json() diff --git a/bot/exts/easter/egg_facts.py b/bot/exts/easter/egg_facts.py index d60032f0..ee383171 100644 --- a/bot/exts/easter/egg_facts.py +++ b/bot/exts/easter/egg_facts.py @@ -12,6 +12,8 @@ from bot.utils.decorators import seasonal_task log = logging.getLogger(__name__) +EGG_FACTS = loads(Path("bot/resources/easter/easter_egg_facts.json").read_text("utf8")) + class EasterFacts(commands.Cog): """ @@ -22,16 +24,8 @@ class EasterFacts(commands.Cog): def __init__(self, bot: Bot): self.bot = bot - self.facts = self.load_json() - self.daily_fact_task = self.bot.loop.create_task(self.send_egg_fact_daily()) - @staticmethod - def load_json() -> dict: - """Load a list of easter egg facts from the resource JSON file.""" - p = Path("bot/resources/easter/easter_egg_facts.json") - return loads(p.read_text("utf8")) - @seasonal_task(Month.APRIL) async def send_egg_fact_daily(self) -> None: """A background task that sends an easter egg fact in the event channel everyday.""" @@ -51,7 +45,7 @@ class EasterFacts(commands.Cog): return discord.Embed( colour=Colours.soft_red, title="Easter Egg Fact", - description=random.choice(self.facts) + description=random.choice(EGG_FACTS) ) |