aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/easter/save_the_planet.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/easter/save_the_planet.py')
-rw-r--r--bot/exts/easter/save_the_planet.py42
1 files changed, 8 insertions, 34 deletions
diff --git a/bot/exts/easter/save_the_planet.py b/bot/exts/easter/save_the_planet.py
index d8bbef20..ff4893a8 100644
--- a/bot/exts/easter/save_the_planet.py
+++ b/bot/exts/easter/save_the_planet.py
@@ -6,49 +6,23 @@ from discord import Embed
from discord.ext import commands
-embeds = []
-
-
-# cog
class SaveThePlanet(commands.Cog):
"""A cog that teaches users how they can help our planet."""
+ json_embeds = []
+
def __init__(self, bot: commands.Bot) -> None:
self.bot = bot
+ with open(Path("bot/resources/save_the_planet.json"), 'r', encoding='utf8') as f:
+ for key, embed in json.load(f).items():
+ self.json_embeds[key] = embed
- def get_response(self) -> Embed:
- """Return a random Embed from the list of embeds."""
- return random.choice(embeds)
-
- @commands.command(aliases=('save_the_earth',))
- async def save_the_planet(self, ctx: commands.Context) -> None:
+ @commands.command(aliases=('savetheearth', 'saveplanet', 'saveearth'))
+ async def savetheplanet(self, ctx: commands.Context) -> None:
"""Responds with a random tip on how to be ecofriendly and help our planet."""
- await ctx.send(embed=self.get_response())
+ await ctx.send(embed=Embed.from_dict(random.choice(self.json_embeds)))
def setup(bot: commands.Bot) -> None:
"""save_the_planet Cog load."""
- with open(Path("bot/resources/easter/save_the_planet.json"), 'r', encoding="utf8") as f:
- responses = json.load(f)
-
- # convert what's in the json to discord embed objects
- for response in responses["embeds"]:
- response["title"] = f"Save the Planet: {response['topic']}"
- response["footer"] = {"text": "The best thing you can do is sharing this information!"}
- response["image"] = {
- "url": response["image_url"]
- }
- response["fields"] = [
- {
- "name": "The Problem",
- "value": response["problem"],
- "inline": False
- },
- {
- "name": "What you can do",
- "value": response["solution"]
- }
- ]
-
- embeds.append(Embed.from_dict(response))
bot.add_cog(SaveThePlanet(bot))