diff options
author | Parker <contact@pkrm.dev> | 2024-12-03 06:05:14 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-03 06:05:14 +0000 |
commit | 15e33831639355546b32477a6870eb0a3ac47e24 (patch) | |
tree | a5455e0a8391747c7226a751354b7236c8c5d40b /code/cogs/skip.py | |
parent | fcbfe460701316ded25e29356ed1fda42386e5c0 (diff) | |
parent | ce18cd27488d90fbd0aae7319a36a89e9fa85aa7 (diff) |
Merge pull request #10 from PacketParker/dev
Update
Diffstat (limited to 'code/cogs/skip.py')
-rw-r--r-- | code/cogs/skip.py | 102 |
1 files changed, 47 insertions, 55 deletions
diff --git a/code/cogs/skip.py b/code/cogs/skip.py index c35a203..7bed931 100644 --- a/code/cogs/skip.py +++ b/code/cogs/skip.py @@ -5,7 +5,7 @@ from discord.ext import commands from cogs.music import Music import asyncio -from utils.config import BOT_COLOR +from utils.config import create_embed from utils.custom_sources import LoadError @@ -22,89 +22,81 @@ class Skip(commands.Cog): "Skips the song that is currently playing" player = self.bot.lavalink.player_manager.get(interaction.guild.id) - embed = discord.Embed(color=BOT_COLOR) - if number != 1: if number < 1: - embed.title = "Invalid Number" - embed.description = "The number option cannot be less than 1" - return await interaction.response.send_message( - embed=embed, ephemeral=True - ) - - elif number > len(player.queue): - embed.title = "Number too Large" - embed.description = ( - "The number you entered is larger than the number of songs" - " in queue. If you want to stop playing music entirely," - " try the </stop:1224840890866991305> command." + embed = create_embed( + title="Invalid Number", + description="The number option cannot be less than 1", ) return await interaction.response.send_message( embed=embed, ephemeral=True ) - else: - for i in range(number - 2, -1, -1): - player.queue.pop(i) - # If there is a next song, get it - try: - next_song = player.queue[0] - except IndexError: - # If the song is on repeat, catch the IndexError and get the current song - # Otherwise, pass - if player.loop == 1: - embed = discord.Embed( - title="Song on Repeat", + elif number > len(player.queue): + embed = create_embed( + title="Number too Large", description=( - "There is nothing in queue, but the current song is on" - " repeat. Use </stop:1224840890866991305> to stop" - " playing music." + "The number you entered is larger than the number of" + " songs in queue. If you want to stop playing music" + " entirely, try the </stop:1224840890866991305>" + " command." ), - color=BOT_COLOR, ) return await interaction.response.send_message( embed=embed, ephemeral=True ) else: - pass + for i in range(number - 2, -1, -1): + player.queue.pop(i) - # Sometimes when a playlist/album of custom source tracks are loaded, one is not able to be found - # so, when a user attempts to skip to that track, we get a LoadError. In this case, just pass it. - try: - await player.skip() - except LoadError: + # If the queue is empty, but the current song is on repeat + if player.loop == 1 and not player.queue: + embed = create_embed( + title="Song on Repeat", + description=( + "There is nothing in queue, but the current song is on" + " repeat. Use </stop:1224840890866991305> to stop" + " playing music." + ), + ) + return await interaction.response.send_message( + embed=embed, ephemeral=True + ) + else: pass - await player.skip() + + # Skip current track, continue skipping on LoadError + while True: + try: + await player.skip() + break + except LoadError as e: + continue if not player.current: - embed = discord.Embed( + embed = create_embed( title="End of Queue", description=( - "All songs in queue have been played. Thank you for using" - f" me :wave:\n\nIssued by: {interaction.user.mention}" + "I have left the voice channel as all songs in the queue" + " have been played.\n\n" + f"Issued by: {interaction.user.mention}" ), - color=BOT_COLOR, ) return await interaction.response.send_message(embed=embed) # It takes a sec for the new track to be grabbed and played # So just wait a sec before sending the message await asyncio.sleep(0.5) - embed = discord.Embed( - title="Track Skipped", + embed = create_embed( + title=( + f"{'Track Skipped' if number == 1 else f'{number} Tracks Skipped'}" + ), description=( - f"**Now Playing: [{next_song.title}]({next_song.uri})** by" - f" {next_song.author}\n\nQueued by:" - f" {next_song.requester.mention}" + f"**[{player.current.title}]({player.current.uri})**" + f" by **{player.current.author}** is now playing\n\n" + f"Issued by: {interaction.user.mention}" ), - color=BOT_COLOR, - ) - embed.set_thumbnail(url=next_song.artwork_url) - embed.set_footer( - text=datetime.datetime.now(datetime.timezone.utc).strftime( - "%Y-%m-%d %H:%M:%S" - ) - + " UTC" + thumbnail=player.current.artwork_url, ) await interaction.response.send_message(embed=embed) |