aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/nowplaying.py
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-03-31 00:12:45 -0500
committerParker <contact@pkrm.dev>2024-03-31 00:12:45 -0500
commit4a8e1001efa18110e64dc5d3f23fbd4a831333c2 (patch)
tree8db92c2dd0cb0b8036b1c05e45860e22f3e359f5 /code/cogs/nowplaying.py
parent23c528ebc000677b8c3e855fad3dbdefa5e4a203 (diff)
Create `np` command
Diffstat (limited to 'code/cogs/nowplaying.py')
-rw-r--r--code/cogs/nowplaying.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/code/cogs/nowplaying.py b/code/cogs/nowplaying.py
new file mode 100644
index 0000000..4f5f6b1
--- /dev/null
+++ b/code/cogs/nowplaying.py
@@ -0,0 +1,45 @@
+import discord
+import datetime
+from discord import app_commands
+from discord.ext import commands
+from cogs.music import Music
+import lavalink
+
+from global_variables import BOT_COLOR
+
+
+class NowPlaying(commands.Cog):
+ def __init__(self, bot):
+ self.bot = bot
+
+
+ @app_commands.command()
+ @app_commands.check(Music.create_player)
+ async def np(self, interaction: discord.Interaction):
+ "Show what song is currently playing"
+ player = self.bot.lavalink.player_manager.get(interaction.guild.id)
+
+ time_in = str(datetime.timedelta(milliseconds=player.position))[:-7]
+ total_duration = lavalink.utils.format_time(player.current.duration)
+ # If total_duration has no hours, then remove the hour part from both times
+ if total_duration.split(":")[0] == "00":
+ time_in = time_in[2:]
+ total_duration = total_duration[3:]
+
+ embed = discord.Embed(
+ title="Now Playing 🎶",
+ description=f"**[{player.current.title}]({player.current.uri})** by {player.current.author}\n{f'` {time_in}/{total_duration} `'}\n\nQueued by: {player.current.requester.mention}",
+ 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)
+
+
+async def setup(bot):
+ await bot.add_cog(NowPlaying(bot))