blob: 4650595a113c5b3abf54420e42e91eba909f4c9c (
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
|
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 get_video(self, genre: Optional[str] = None) -> dict:
"""
Picks a random anthem from the list.
If `genre` is supplied, it will pick from videos attributed with that genre.
If none can be found, it will log this as well as provide that information to the user.
"""
if not genre:
return random.choice(self.anthems)
else:
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.")
@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.
If `genre` is supplied, it will select from that genre only.
"""
anthem = self.get_video(genre)
if anthem:
await ctx.send(anthem["url"])
else:
await ctx.send("I couldn't find a video, sorry!")
def setup(bot: Bot) -> None:
"""Load the Pride Anthem Cog."""
bot.add_cog(PrideAnthem())
|