diff --git a/config/config.py b/config/config.py index aef54c94..69fcd527 100644 --- a/config/config.py +++ b/config/config.py @@ -71,6 +71,8 @@ HELP_RESUME_LONG = "Resumes the AudioPlayer." HELP_SKIP_SHORT = "Skip a song" HELP_SKIP_LONG = "Skips the currently playing song and goes to the next item in the queue." +HELP_REMOVE_SHORT = "Remove a song fomm the queue." +HELP_REMOVE_LONG = "Enter a queue position number to remove the song." HELP_SONGINFO_SHORT = "Info about current Song" HELP_SONGINFO_LONG = "Shows details about the song currently being played and posts a link to the song." HELP_STOP_SHORT = "Stop Music" @@ -90,4 +92,4 @@ HELP_CHANGECHANNEL_SHORT = "Change the bot channel" HELP_CHANGECHANNEL_LONG = "Change the bot channel to the VC you are in" -ABSOLUTE_PATH = '' #do not modify \ No newline at end of file +ABSOLUTE_PATH = '' #do not modify diff --git a/musicbot/audiocontroller.py b/musicbot/audiocontroller.py index 7d05eb84..a03c5473 100644 --- a/musicbot/audiocontroller.py +++ b/musicbot/audiocontroller.py @@ -52,6 +52,14 @@ def track_history(self): history_string += "\n" + trackname return history_string + def remove_song(self, queue_number): + removed_title = self.playlist.get_title(queue_number) + if removed_title is None: + return "Queue position \"" + str(queue_number) + "\" does not exist." + success_str = "Removed track \#" + str(queue_number) + ": " + removed_title + self.playlist.remove(queue_number) + return success_str + def next_song(self, error): """Invoked after a song is finished. Plays the next song if there is one.""" diff --git a/musicbot/commands/music.py b/musicbot/commands/music.py index 2bed1a23..fab3d747 100644 --- a/musicbot/commands/music.py +++ b/musicbot/commands/music.py @@ -183,6 +183,18 @@ async def _skip(self, ctx): current_guild.voice_client.stop() await ctx.send("Skipped current song :fast_forward:") + @commands.command(name='remove', description=config.HELP_REMOVE_LONG, help=config.HELP_REMOVE_SHORT, aliases=['rm']) + async def _remove(self, ctx, *, queue_number: int): + current_guild = utils.get_guild(self.bot, ctx.message) + + if queue_number is None: + ctx.send("You must enter a queue position to remove a song.") + + audiocontroller = utils.guild_to_audiocontroller[current_guild] + + response = audiocontroller.remove_song(queue_number) + await ctx.send(response) + @commands.command(name='clear', description=config.HELP_CLEAR_LONG, help=config.HELP_CLEAR_SHORT, aliases=['cl']) async def _clear(self, ctx): current_guild = utils.get_guild(self.bot, ctx.message) diff --git a/musicbot/playlist.py b/musicbot/playlist.py index 1ba81e7f..899bdd28 100644 --- a/musicbot/playlist.py +++ b/musicbot/playlist.py @@ -28,6 +28,11 @@ def add_name(self, trackname): def add(self, track): self.playque.append(track) + def remove(self, queue_number): + if queue_number > len(self.playque): + return + del self.playque[queue_number-1] + def next(self, song_played): if self.loop == True: @@ -62,3 +67,8 @@ def shuffle(self): def empty(self): self.playque.clear() self.playhistory.clear() + + def get_title(self, queue_number): + if queue_number > len(self.playque): + return None + return self.playque[queue_number-1].info.title