From 787db1d6e6e09b649e115f062026d821cc1d4682 Mon Sep 17 00:00:00 2001 From: Rafael Vargas Date: Thu, 30 Dec 2021 17:49:56 -0400 Subject: [PATCH] Adding move song command --- vulkanbot/music/Music.py | 19 +++++++++++++++++++ vulkanbot/music/Playlist.py | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/vulkanbot/music/Music.py b/vulkanbot/music/Music.py index 7cb5c75..41368cb 100644 --- a/vulkanbot/music/Music.py +++ b/vulkanbot/music/Music.py @@ -205,6 +205,25 @@ class Music(commands.Cog): await self.__send_embed(ctx, description='Musicas embaralhadas', colour_name='blue') + @commands.command(name='move', help='Manda uma música de uma posição para outra ') + async def move(self, ctx, pos1, pos2='1'): + try: + pos1 = int(pos1) + pos2 = int(pos2) + + except Exception as e: + print(e) + await ctx.send('This command require a number') + return + + success, reason = self.__playlist.move_songs(pos1, pos2) + + if not success: + songs = self.__playlist.songs_to_preload + await self.__downloader.preload(songs) + await ctx.send(reason) + else: + await ctx.send(reason) def setup(bot): bot.add_cog(Music(bot)) diff --git a/vulkanbot/music/Playlist.py b/vulkanbot/music/Playlist.py index 1e427bc..fb27da1 100644 --- a/vulkanbot/music/Playlist.py +++ b/vulkanbot/music/Playlist.py @@ -139,3 +139,23 @@ class Playlist(IPlaylist): if song == song_destroy: self.__queue.remove(song) break + + def move_songs(self, pos1, pos2) -> tuple: + """Receive two position and try to chance the songs in those positions + + Positions: First music is 1 + Return (Error bool, string) with the status of the function, to show to user + """ + if pos2 not in range(1, len(self.__queue)) or pos1 not in range(1, len(self.__queue)): + return (False, 'Numbers need to be more than 0 and less than the queue length') + + try: + song1 = self.__queue[pos1-1] + song2 = self.__queue[pos2-1] + + self.__queue[pos1-1] = song2 + self.__queue[pos2-1] = song1 + return (True, 'Songs moved with successfully') + except Exception as e: + print(e) + return (False, 'There was a problem with the moving of songs') \ No newline at end of file