mirror of
https://github.com/deadcxap/YandexMusicDiscordBot.git
synced 2026-01-10 12:41:44 +03:00
impr: Changed /account playlists functionality
This commit is contained in:
@@ -6,19 +6,6 @@ from discord import ApplicationContext, ButtonStyle, Interaction, Embed
|
||||
|
||||
from MusicBot.cogs.utils.voice_extension import VoiceExtension
|
||||
|
||||
def generate_playlists_embed(page: int, playlists: list[tuple[str, int]]) -> Embed:
|
||||
count = 15 * page
|
||||
length = len(playlists)
|
||||
embed = Embed(
|
||||
title=f"Всего плейлистов: {length}",
|
||||
color=0xfed42b
|
||||
)
|
||||
embed.set_author(name="Ваши плейлисты")
|
||||
embed.set_footer(text=f"Страница {page + 1} из {ceil(length / 10)}")
|
||||
for playlist in playlists[count:count + 10]:
|
||||
embed.add_field(name=playlist[0], value=f"{playlist[1]} треков", inline=False)
|
||||
return embed
|
||||
|
||||
def generate_queue_embed(page: int, tracks_list: list[dict[str, Any]]) -> Embed:
|
||||
count = 15 * page
|
||||
length = len(tracks_list)
|
||||
@@ -36,61 +23,6 @@ def generate_queue_embed(page: int, tracks_list: list[dict[str, Any]]) -> Embed:
|
||||
embed.add_field(name=f"{i} - {track['title']} - {duration_m}:{duration_s:02d}", value="", inline=False)
|
||||
return embed
|
||||
|
||||
|
||||
class MPNextButton(Button, VoiceExtension):
|
||||
def __init__(self, **kwargs):
|
||||
Button.__init__(self, **kwargs)
|
||||
VoiceExtension.__init__(self, None)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
if not interaction.user:
|
||||
return
|
||||
user = await self.users_db.get_user(interaction.user.id)
|
||||
page = user['playlists_page'] + 1
|
||||
await self.users_db.update(interaction.user.id, {'playlists_page': page})
|
||||
embed = generate_playlists_embed(page, user['playlists'])
|
||||
await interaction.edit(embed=embed, view=await MyPlaylists(interaction).init())
|
||||
|
||||
class MPPrevButton(Button, VoiceExtension):
|
||||
def __init__(self, **kwargs):
|
||||
Button.__init__(self, **kwargs)
|
||||
VoiceExtension.__init__(self, None)
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
if not interaction.user:
|
||||
return
|
||||
user = await self.users_db.get_user(interaction.user.id)
|
||||
page = user['playlists_page'] - 1
|
||||
await self.users_db.update(interaction.user.id, {'playlists_page': page})
|
||||
embed = generate_playlists_embed(page, user['playlists'])
|
||||
await interaction.edit(embed=embed, view=await MyPlaylists(interaction).init())
|
||||
|
||||
class MyPlaylists(View, VoiceExtension):
|
||||
def __init__(self, ctx: ApplicationContext | Interaction, *items: Item, timeout: float | None = 360, disable_on_timeout: bool = True):
|
||||
View.__init__(self, *items, timeout=timeout, disable_on_timeout=disable_on_timeout)
|
||||
VoiceExtension.__init__(self, None)
|
||||
|
||||
self.ctx = ctx
|
||||
self.next_button = MPNextButton(style=ButtonStyle.primary, emoji='▶️')
|
||||
self.prev_button = MPPrevButton(style=ButtonStyle.primary, emoji='◀️')
|
||||
|
||||
async def init(self) -> Self:
|
||||
if not self.ctx.user:
|
||||
return self
|
||||
|
||||
user = await self.users_db.get_user(self.ctx.user.id)
|
||||
count = 10 * user['playlists_page']
|
||||
|
||||
if not user['playlists'][count + 10:]:
|
||||
self.next_button.disabled = True
|
||||
if not user['playlists'][:count]:
|
||||
self.prev_button.disabled = True
|
||||
|
||||
self.add_item(self.prev_button)
|
||||
self.add_item(self.next_button)
|
||||
|
||||
return self
|
||||
|
||||
class QueueNextButton(Button, VoiceExtension):
|
||||
def __init__(self, **kwargs):
|
||||
Button.__init__(self, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user