diff options
author | Parker <contact@pkrm.dev> | 2024-08-02 21:37:00 -0500 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-08-02 21:37:00 -0500 |
commit | 9e1729aa290501e5a3da546455fe68e8c13ce212 (patch) | |
tree | 49d1c9f92a7493129b923455b768c6ab96048693 /code/cogs | |
parent | 1bffa26776f6c80e2f2513d236f78ce9b7eea39f (diff) |
Change config validation - make more stuff optional
Diffstat (limited to 'code/cogs')
-rw-r--r-- | code/cogs/help.py | 3 | ||||
-rw-r--r-- | code/cogs/lyrics.py | 78 | ||||
-rw-r--r-- | code/cogs/play.py | 8 |
3 files changed, 88 insertions, 1 deletions
diff --git a/code/cogs/help.py b/code/cogs/help.py index 3746482..a15d6d2 100644 --- a/code/cogs/help.py +++ b/code/cogs/help.py @@ -88,7 +88,8 @@ commands_and_descriptions = { class HelpView(discord.ui.View): def __init__(self, timeout=180.0): super().__init__(timeout=timeout) - self.add_item(discord.ui.Button(label="Invite Me", url=BOT_INVITE_LINK, row=1)) + if BOT_INVITE_LINK: + self.add_item(discord.ui.Button(label="Invite Me", url=BOT_INVITE_LINK, row=1)) @discord.ui.button( label="View All Commands", style=discord.ButtonStyle.green, row=1 diff --git a/code/cogs/lyrics.py b/code/cogs/lyrics.py new file mode 100644 index 0000000..711084f --- /dev/null +++ b/code/cogs/lyrics.py @@ -0,0 +1,78 @@ +import discord +import datetime +from discord import app_commands +from discord.ext import commands +from cogs.music import Music + +from utils.config import BOT_COLOR + + +class Lyrics(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @app_commands.command() + @app_commands.check(Music.create_player) + async def lyrics(self, interaction: discord.Interaction): + "Get lyrics for the song that is currently playing" + player = self.bot.lavalink.player_manager.get(interaction.guild.id) + + # If the Genius API client is not setup, send an error message + if self.bot.genius is not None: + embed = discord.Embed( + title="Lyrics Feature Error", + description="The lyrics feature is currently disabled due to errors with the Genius API.", + color=BOT_COLOR, + ) + embed.set_footer( + text=datetime.datetime.now(datetime.timezone.utc).strftime( + "%Y-%m-%d %H:%M:%S" + ) + + " UTC" + ) + return await interaction.response.send_message(embed=embed, ephemeral=True) + + # Search for the songs lyrics with Genius + song = self.bot.genius.search_song(player.current.title, player.current.author) + + # If no lyrics are found, send an error message + if song is None: + embed = discord.Embed( + title="Lyrics Not Found", + description="Unfortunately, I wasn't able to find any lyrics for the song that is currently playing.", + color=BOT_COLOR, + ) + embed.set_thumbnail(url=player.current.artwork_url) + embed.set_footer( + text=datetime.datetime.now(datetime.timezone.utc).strftime( + "%Y-%m-%d %H:%M:%S" + ) + + " UTC" + ) + + return await interaction.response.send_message(embed=embed, ephemeral=True) + + # Remove unwanted text + lyrics = song.lyrics + lyrics = lyrics.split(" Lyrics", 1)[-1] + lyrics = lyrics.replace("You might also like", "\n") + lyrics = lyrics[:-7] + + embed = discord.Embed( + title=f"Lyrics for {player.current.title} by {player.current.author}", + description=lyrics, + color=BOT_COLOR, + ) + embed.set_thumbnail(url=player.current.artwork_url) + embed.set_footer( + text=datetime.datetime.now(datetime.timezone.utc).strftime( + "%Y-%m-%d %H:%M:%S" + ) + + " UTC" + ) + + await interaction.response.send_message(embed=embed, ephemeral=True) + + +async def setup(bot): + await bot.add_cog(Lyrics(bot)) diff --git a/code/cogs/play.py b/code/cogs/play.py index db21cf7..fdd0233 100644 --- a/code/cogs/play.py +++ b/code/cogs/play.py @@ -147,6 +147,14 @@ class Play(commands.Cog): ### elif "open.spotify.com" in query: + if not self.bot.spotify_headers: + embed = discord.Embed( + title="Spotify Error", + description="Spotify support seems to be broken at the moment. Please try again and fill out a bug report with </bug:1224840889906499626> if this continues to happen.", + color=BOT_COLOR, + ) + return await interaction.response.send_message(embed=embed, ephemeral=True) + embed = discord.Embed(color=BOT_COLOR) if "open.spotify.com/playlist" in query: |