[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
This commit is contained in:
aikaterna 2018-07-11 19:01:11 -07:00 committed by Kowlin
parent 43c7bd48c7
commit 2df282222f

View File

@ -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,