diff options
Diffstat (limited to 'bot/exts/holidays/easter/egg_facts.py')
| -rw-r--r-- | bot/exts/holidays/easter/egg_facts.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/bot/exts/holidays/easter/egg_facts.py b/bot/exts/holidays/easter/egg_facts.py new file mode 100644 index 00000000..5f216e0d --- /dev/null +++ b/bot/exts/holidays/easter/egg_facts.py @@ -0,0 +1,55 @@ +import logging +import random +from json import loads +from pathlib import Path + +import discord +from discord.ext import commands + +from bot.bot import Bot +from bot.constants import Channels, Colours, Month +from bot.utils.decorators import seasonal_task + +log = logging.getLogger(__name__) + +EGG_FACTS = loads(Path("bot/resources/holidays/easter/easter_egg_facts.json").read_text("utf8")) + + +class EasterFacts(commands.Cog): + """ + A cog contains a command that will return an easter egg fact when called. + + It also contains a background task which sends an easter egg fact in the event channel everyday. + """ + + def __init__(self, bot: Bot): + self.bot = bot + self.daily_fact_task = self.bot.loop.create_task(self.send_egg_fact_daily()) + + @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.""" + await self.bot.wait_until_guild_available() + + channel = self.bot.get_channel(Channels.community_bot_commands) + await channel.send(embed=self.make_embed()) + + @commands.command(name="eggfact", aliases=("fact",)) + async def easter_facts(self, ctx: commands.Context) -> None: + """Get easter egg facts.""" + embed = self.make_embed() + await ctx.send(embed=embed) + + @staticmethod + def make_embed() -> discord.Embed: + """Makes a nice embed for the message to be sent.""" + return discord.Embed( + colour=Colours.soft_red, + title="Easter Egg Fact", + description=random.choice(EGG_FACTS) + ) + + +def setup(bot: Bot) -> None: + """Load the Easter Egg facts Cog.""" + bot.add_cog(EasterFacts(bot)) |