diff options
| author | 2019-04-09 21:40:30 +0530 | |
|---|---|---|
| committer | 2019-04-09 21:40:30 +0530 | |
| commit | 0d0833849abcfe56fc0582cb1cf168e93cd4a588 (patch) | |
| tree | 1337331351b72c8b29d1399dbe72fd27852eb8e1 /bot/seasons | |
| parent | Merge branch 'master' of https://github.com/python-discord/seasonalbot (diff) | |
done with the easter egg fact cmd and background task
Diffstat (limited to 'bot/seasons')
| -rw-r--r-- | bot/seasons/easter/egg_facts.py | 46 | 
1 files changed, 46 insertions, 0 deletions
| diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py new file mode 100644 index 00000000..1080f6c6 --- /dev/null +++ b/bot/seasons/easter/egg_facts.py @@ -0,0 +1,46 @@ +from discord.ext import commands +import discord +import asyncio +from pathlib import Path +from json import load +import random +from bot.constants import Colours + + +class EasterFacts(commands.Cog): + +    def __init__(self, bot): +        self.bot = bot +        self.facts = self.load_json() + +    @staticmethod +    def load_json(): +        p = Path('bot', 'resources', 'easter', 'easter_egg_facts.json') +        with p.open(encoding="utf8") as f: +            facts = load(f) +        return facts + +    async def background(self): +        channel = self.bot.get_channel(426566445124812815) +        while True: +            embed = self.make_embed() +            await channel.send(embed=embed) +            await asyncio.sleep(24*60*60) + +    @commands.command(name='eggfact', aliases=['fact']) +    async def easter_facts(self, ctx): +        embed = self.make_embed() +        await ctx.send(embed=embed) + +    def make_embed(self): +        embed = discord.Embed() +        embed.colour = Colours.soft_red +        embed.title = 'Easter Egg Fact' +        random_fact = random.choice(self.facts['facts']) +        embed.description = random_fact +        return embed + + +def setup(bot): +    bot.loop.create_task(EasterFacts(bot).background()) +    bot.add_cog(EasterFacts(bot)) | 
