aboutsummaryrefslogtreecommitdiff
path: root/code/cogs
diff options
context:
space:
mode:
Diffstat (limited to 'code/cogs')
-rw-r--r--code/cogs/help.py7
-rw-r--r--code/cogs/lyrics.py78
-rw-r--r--code/cogs/news.py5
-rw-r--r--code/cogs/play.py8
4 files changed, 97 insertions, 1 deletions
diff --git a/code/cogs/help.py b/code/cogs/help.py
index 3746482..97af668 100644
--- a/code/cogs/help.py
+++ b/code/cogs/help.py
@@ -70,6 +70,10 @@ commands_and_descriptions = {
"description": "Resume the song that is currently paused",
"usage": "/resume",
},
+ "lyrics": {
+ "description": "Get the lyrics of the song that is currently playing",
+ "usage": "/lyrics",
+ },
"news": {
"description": "Get recent news and updates about the bot",
"usage": "/news",
@@ -88,7 +92,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..b3a918f
--- /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 not self.bot.genius:
+ 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/news.py b/code/cogs/news.py
index c115559..9013567 100644
--- a/code/cogs/news.py
+++ b/code/cogs/news.py
@@ -19,6 +19,11 @@ class News(commands.Cog):
)
embed.add_field(
+ name="**Lyrics!**",
+ value="> You can now get lyrics for the song that is currently playing. Just use the `/lyrics` command! Some songs may not have lyrics available, but the bot will do its best to find them.",
+ )
+
+ embed.add_field(
name="**Apple Music Support!**",
value="> After some trial and error, you can now play music through Apple Music links. Just paste the link and the bot will do the rest!",
)
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: