diff options
| author | 2021-04-13 00:41:37 +0300 | |
|---|---|---|
| committer | 2021-04-13 00:41:37 +0300 | |
| commit | eb999d127d68932fa08770919acce2c87f656225 (patch) | |
| tree | 10ee57ec7d876506e41613c274319b45de8b6e79 /bot/exts | |
| parent | Merge pull request #678 from python-discord/remove-inappropriate-riddle (diff) | |
| parent | Merge branch 'main' into fix/april-fools-video-categories (diff) | |
Merge pull request #676 from python-discord/fix/april-fools-video-categories
fix: put april fools video links in correct channel names
Diffstat (limited to 'bot/exts')
| -rw-r--r-- | bot/exts/easter/april_fools_vids.py | 26 | 
1 files changed, 8 insertions, 18 deletions
| diff --git a/bot/exts/easter/april_fools_vids.py b/bot/exts/easter/april_fools_vids.py index efe7e677..c7a3c014 100644 --- a/bot/exts/easter/april_fools_vids.py +++ b/bot/exts/easter/april_fools_vids.py @@ -1,36 +1,26 @@  import logging  import random  from json import load -from pathlib import Path  from discord.ext import commands  log = logging.getLogger(__name__) +with open("bot/resources/easter/april_fools_vids.json", encoding="utf-8") as f: +    ALL_VIDS = load(f) +  class AprilFoolVideos(commands.Cog):      """A cog for April Fools' that gets a random April Fools' video from Youtube.""" -    def __init__(self, bot: commands.Bot): -        self.bot = bot -        self.yt_vids = self.load_json() -        self.youtubers = ['google']  # will add more in future - -    @staticmethod -    def load_json() -> dict: -        """A function to load JSON data.""" -        p = Path('bot/resources/easter/april_fools_vids.json') -        with p.open(encoding="utf-8") as json_file: -            all_vids = load(json_file) -        return all_vids -      @commands.command(name='fool')      async def april_fools(self, ctx: commands.Context) -> None:          """Get a random April Fools' video from Youtube.""" -        random_youtuber = random.choice(self.youtubers) -        category = self.yt_vids[random_youtuber] -        random_vid = random.choice(category) -        await ctx.send(f"Check out this April Fools' video by {random_youtuber}.\n\n{random_vid['link']}") +        video = random.choice(ALL_VIDS) + +        channel, url = video["channel"], video["url"] + +        await ctx.send(f"Check out this April Fools' video by {channel}.\n\n{url}")  def setup(bot: commands.Bot) -> None: | 
