diff options
Diffstat (limited to 'bot')
-rw-r--r-- | bot/exts/easter/save_the_planet.py | 47 | ||||
-rw-r--r-- | bot/resources/easter/save_the_planet.json | 52 |
2 files changed, 49 insertions, 50 deletions
diff --git a/bot/exts/easter/save_the_planet.py b/bot/exts/easter/save_the_planet.py index 4ea7a5fb..ff4893a8 100644 --- a/bot/exts/easter/save_the_planet.py +++ b/bot/exts/easter/save_the_planet.py @@ -1,49 +1,28 @@ -from discord.ext import commands +import json +import random from pathlib import Path + from discord import Embed -import random -import json +from discord.ext import commands -embeds = [] 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 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 https://discord.com/developers/docs/resources/channel#embed-object - 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)) diff --git a/bot/resources/easter/save_the_planet.json b/bot/resources/easter/save_the_planet.json index 83c4a966..a8aa1f31 100644 --- a/bot/resources/easter/save_the_planet.json +++ b/bot/resources/easter/save_the_planet.json @@ -1,17 +1,37 @@ -{ - "embeds": [ - { - "topic": "Choose Reneweable Energy", - "image_url": "https://cdn.dnaindia.com/sites/default/files/styles/full/public/2019/07/23/851602-renewable-energy-istock-072419.jpg", - "problem": "Getting energy from oil or fossil fuels isn't a good idea, because there is only so much of it.", - "solution": "Use renewable energy, such as wind, solar, and hydro, because it is healthier and is not a finite resource!" - }, +[ + { + "title": "Save the Planet: Choose Reneweable Energy", + "image": {"url": "https://cdn.dnaindia.com/sites/default/files/styles/full/public/2019/07/23/851602-renewable-energy-istock-072419.jpg"}, + "fields": [ + { + "name": "The Problem", + "value": "Getting energy from oil or fossil fuels isn't a good idea, because there is only so much of it.", + "inline": false + }, - { - "topic": "Save the Trees!", - "image_url": "https://www.thecollegesolution.com/wp-content/uploads/2014/07/crumpled-paper-1.jpg", - "problem": "We often waste trees on making paper, and just getting rid of them for no good reason.", - "solution": "Make sure you only use paper when absolutely neccesary. Find ways to plant trees (participate in Hacktober!) to combat losing them." - } - ] -}
\ No newline at end of file + { + "name": "What you can do", + "value": "Use renewable energy, such as wind, solar, and hydro, because it is healthier and is not a finite resource!", + "inline": false + } + ] + }, + + { + "title": "Save the Planet: Save the Trees!", + "image": {"url": "https://www.thecollegesolution.com/wp-content/uploads/2014/07/crumpled-paper-1.jpg"}, + "fields": [ + { + "name": "The Problem", + "value": "We often waste trees on making paper, and just getting rid of them for no good reason.", + "inline": false + }, + + { + "name": "What you can do", + "value": "Make sure you only use paper when absolutely neccesary. Find ways to plant trees (Hacktober Fest!) to combat losing them.", + "inline": false + } + ] + } +] |