Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V3 Audio] Playlist list and notify msg changes #2155

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[V3 Audio] Playlist list and notify msg changes
aikaterna authored Sep 29, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 50d20b559e6ce2bf4a9c4da80c407d7a3c2e5745
55 changes: 49 additions & 6 deletions redbot/cogs/audio/audio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import contextlib

import aiohttp
import asyncio
import datetime
@@ -133,11 +131,20 @@ async def event_handler(self, player, event_type, extra):
description = "{}".format(player.current.uri.replace("localtracks/", ""))
else:
description = "**[{}]({})**".format(player.current.title, player.current.uri)
if player.current.is_stream:
dur = "LIVE"
else:
dur = lavalink.utils.format_time(player.current.length)
embed = discord.Embed(
colour=(await self._get_embed_colour(notify_channel)),
title="Now Playing",
description=description,
)
embed.set_footer(
text="Track length: {} | Requested by: {}".format(
dur, player.current.requester
)
)
if (
await self.config.guild(player.channel.guild).thumbnail()
and player.current.thumbnail
@@ -1045,17 +1052,51 @@ async def _playlist_info(self, ctx, playlist_name):
async def _playlist_list(self, ctx):
"""List saved playlists."""
playlists = await self.config.guild(ctx.guild).playlists.get_raw()
if not playlists:
return await self._embed_msg(ctx, "No saved playlists.")
playlist_list = []
space = "\N{EN SPACE}"
for playlist_name in playlists:
playlist_list.append(playlist_name)
tracks = playlists[playlist_name]["tracks"]
if not tracks:
tracks = []
author = playlists[playlist_name]["author"]
playlist_list.append(
"**{}**\n{}Tracks: {}\n{}Author: {}\n".format(
playlist_name,
(space * 4),
str(len(tracks)),
(space * 4),
self.bot.get_user(author),
)
)
abc_names = sorted(playlist_list, key=str.lower)
all_playlists = ", ".join(abc_names)
len_playlist_list_pages = math.ceil(len(abc_names) / 5)
playlist_embeds = []
for page_num in range(1, len_playlist_list_pages + 1):
embed = await self._build_playlist_list_page(ctx, page_num, abc_names)
playlist_embeds.append(embed)
await menu(ctx, playlist_embeds, DEFAULT_CONTROLS)

async def _build_playlist_list_page(self, ctx, page_num, abc_names):
plist_num_pages = math.ceil(len(abc_names) / 5)
plist_idx_start = (page_num - 1) * 5
plist_idx_end = plist_idx_start + 5
plist = ""
for i, playlist_info in enumerate(
abc_names[plist_idx_start:plist_idx_end], start=plist_idx_start
):
item_idx = i + 1
plist += "`{}.` {}".format(item_idx, playlist_info)
embed = discord.Embed(
colour=await ctx.embed_colour(),
title="Playlists for {}:".format(ctx.guild.name),
description=all_playlists,
description=plist,
)
await ctx.send(embed=embed)
embed.set_footer(
text="Page {}/{} | {} playlists".format(page_num, plist_num_pages, len(abc_names))
)
return embed

@commands.cooldown(1, 15, discord.ext.commands.BucketType.guild)
@playlist.command(name="queue")
@@ -2131,6 +2172,8 @@ async def volume(self, ctx, vol: int = None):
ctx, ctx.author
):
return await self._embed_msg(ctx, "You need the DJ role to change the volume.")
if vol < 0:
vol = 0
if vol > 150:
vol = 150
await self.config.guild(ctx.guild).volume.set(vol)