diff options
| author | 2021-05-20 18:30:07 +0530 | |
|---|---|---|
| committer | 2021-05-20 18:30:07 +0530 | |
| commit | d032dd1a0e0fb0f866b1b492f917990d66dae55a (patch) | |
| tree | 0adfc37d1350c7eb0b33ea44d4170a44a017e119 /bot/exts/pride/pride_anthem.py | |
| parent | Merge remote-tracking branch 'origin/feature/command-suggestions' into featur... (diff) | |
| parent | Merge pull request #733 from Icebluewolf/http_status_command_randomness (diff) | |
Merge branch 'main' into feature/command-suggestions
Diffstat (limited to 'bot/exts/pride/pride_anthem.py')
| -rw-r--r-- | bot/exts/pride/pride_anthem.py | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/bot/exts/pride/pride_anthem.py b/bot/exts/pride/pride_anthem.py index 33cb2a9d..4650595a 100644 --- a/bot/exts/pride/pride_anthem.py +++ b/bot/exts/pride/pride_anthem.py @@ -2,20 +2,21 @@ import json import logging import random from pathlib import Path +from typing import Optional from discord.ext import commands +from bot.bot import Bot + log = logging.getLogger(__name__) +VIDEOS = json.loads(Path("bot/resources/pride/anthems.json").read_text("utf8")) + class PrideAnthem(commands.Cog): """Embed a random youtube video for a gay anthem!""" - def __init__(self, bot: commands.Bot): - self.bot = bot - self.anthems = self.load_vids() - - def get_video(self, genre: str = None) -> dict: + def get_video(self, genre: Optional[str] = None) -> dict: """ Picks a random anthem from the list. @@ -25,20 +26,13 @@ class PrideAnthem(commands.Cog): if not genre: return random.choice(self.anthems) else: - songs = [song for song in self.anthems if genre.casefold() in song["genre"]] + songs = [song for song in VIDEOS if genre.casefold() in song["genre"]] try: return random.choice(songs) except IndexError: log.info("No videos for that genre.") - @staticmethod - def load_vids() -> list: - """Loads a list of videos from the resources folder as dictionaries.""" - with open(Path("bot/resources/pride/anthems.json"), "r", encoding="utf8") as f: - anthems = json.load(f) - return anthems - - @commands.command(name="prideanthem", aliases=["anthem", "pridesong"]) + @commands.command(name="prideanthem", aliases=("anthem", "pridesong")) async def prideanthem(self, ctx: commands.Context, genre: str = None) -> None: """ Sends a message with a video of a random pride anthem. @@ -52,6 +46,6 @@ class PrideAnthem(commands.Cog): await ctx.send("I couldn't find a video, sorry!") -def setup(bot: commands.Bot) -> None: - """Cog loader for pride anthem.""" - bot.add_cog(PrideAnthem(bot)) +def setup(bot: Bot) -> None: + """Load the Pride Anthem Cog.""" + bot.add_cog(PrideAnthem()) |