From 2df282222fdb437c24d86bfd919e8cfecb5dd7ac Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Wed, 11 Jul 2018 19:01:11 -0700 Subject: [PATCH] [V3 Audio] Fix for playlist queue duplicates (#1890) * [V3 Audio] Fix for playlist queue duplicates And some sanitizing of playlist names. * [V3 Audio] Playlist naming standardization Enforced single-word playlist name across all playlist commands, removed A-Z 0-9 name standardization. [p]playlist delete will still accept playlist names with quotes as there should be a way to remove already-existing playlists with spaces in their name. * [V3 Audio] Black formatting --- redbot/cogs/audio/audio.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/redbot/cogs/audio/audio.py b/redbot/cogs/audio/audio.py index d2aa0a83d..7237d7aa4 100644 --- a/redbot/cogs/audio/audio.py +++ b/redbot/cogs/audio/audio.py @@ -714,6 +714,7 @@ class Audio: return await self._embed_msg( ctx, "Playlist name already exists, try again with a different name." ) + playlist_name = playlist_name.split(" ")[0].strip('"') playlist_list = self._to_json(ctx, None, None) async with self.config.guild(ctx.guild).playlists() as playlists: playlists[playlist_name] = playlist_list @@ -775,6 +776,7 @@ class Audio: ) await ctx.send(embed=embed) + @commands.cooldown(1, 15, discord.ext.commands.BucketType.guild) @playlist.command(name="queue") async def _playlist_queue(self, ctx, playlist_name=None): """Save the queue to a playlist.""" @@ -801,11 +803,11 @@ class Audio: await self._embed_msg(ctx, "Please enter a name for this playlist.") def check(m): - return m.author == ctx.author + return m.author == ctx.author and not m.content.startswith(ctx.prefix) try: playlist_name_msg = await ctx.bot.wait_for("message", timeout=15.0, check=check) - playlist_name = str(playlist_name_msg.content) + playlist_name = playlist_name_msg.content.split(" ")[0].strip('"') if len(playlist_name) > 20: return await self._embed_msg(ctx, "Try the command again with a shorter name.") if playlist_name in playlists: @@ -816,11 +818,12 @@ class Audio: return await self._embed_msg(ctx, "No playlist name entered, try again later.") playlist_list = self._to_json(ctx, None, tracklist) async with self.config.guild(ctx.guild).playlists() as playlists: + playlist_name = playlist_name.split(" ")[0].strip('"') playlists[playlist_name] = playlist_list await self._embed_msg( ctx, "Playlist {} saved from current queue: {} tracks added.".format( - playlist_name, len(tracklist) + playlist_name.split(" ")[0].strip('"'), len(tracklist) ), ) @@ -868,6 +871,7 @@ class Audio: playlist_list = self._to_json(ctx, playlist_url, tracklist) if tracklist is not None: async with self.config.guild(ctx.guild).playlists() as playlists: + playlist_name = playlist_name.split(" ")[0].strip('"') playlists[playlist_name] = playlist_list return await self._embed_msg( ctx,