aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/holidays/easter/egg_facts.py
blob: 0e746c296350d623288b5beb0d31911d7a6b1878 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import random
from json import loads
from pathlib import Path

import discord
from discord.ext import commands
from pydis_core.utils.logging import get_logger

from bot.bot import Bot
from bot.constants import Channels, Colours, Month
from bot.utils.decorators import seasonal_task

log = get_logger(__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."""
        channel = self.bot.get_channel(Channels.sir_lancebot_playground)
        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)
        )


async def setup(bot: Bot) -> None:
    """Load the Easter Egg facts Cog."""
    await bot.add_cog(EasterFacts(bot))