feat(commands/voice/playing): add --description

This commit is contained in:
Ryan 2025-01-06 10:30:48 -05:00
parent d9d35a2672
commit d3fd79e87f
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
2 changed files with 36 additions and 3 deletions

View File

@ -216,17 +216,50 @@ async def playing(message):
if not command_allowed(message): if not command_allowed(message):
return return
tokens = commands.tokenize(message.content)
parser = arguments.ArgumentParser(
tokens[0], "get information about the currently playing song"
)
parser.add_argument(
"-d",
"--description",
action="store_true",
help="get the description",
)
if not (args := await parser.parse_args(message, tokens)):
return
if source := message.guild.voice_client.source: if source := message.guild.voice_client.source:
if args.description:
if description := source.description:
paginator = disnake_paginator.ButtonPaginator(
invalid_user_function=utils.invalid_user_handler,
color=constants.EMBED_COLOR,
title=source.title,
segments=disnake_paginator.split(description),
)
for embed in paginator.embeds:
embed.url = source.original_url
await paginator.start(
disnake_paginator.wrappers.MessageInteractionWrapper(message)
)
else:
await utils.reply(
message,
source.description or "no description found!",
)
return
bar_length = 35 bar_length = 35
progress = source.original.progress / source.duration progress = source.original.progress / source.duration
embed = disnake.Embed( embed = disnake.Embed(
color=constants.EMBED_COLOR, color=constants.EMBED_COLOR,
title=source.title, title=source.title,
url=source.original_url,
description=f"{'⏸️ ' if message.guild.voice_client.is_paused() else ''}" description=f"{'⏸️ ' if message.guild.voice_client.is_paused() else ''}"
f"`[{'#'*int(progress * bar_length)}{'-'*int((1 - progress) * bar_length)}]` " f"`[{'#'*int(progress * bar_length)}{'-'*int((1 - progress) * bar_length)}]` "
f"**{youtubedl.format_duration(int(source.original.progress))}** / **{youtubedl.format_duration(source.duration)}** (**{round(progress * 100)}%**)", f"**{youtubedl.format_duration(int(source.original.progress))}** / **{youtubedl.format_duration(source.duration)}** (**{round(progress * 100)}%**)",
url=source.original_url,
) )
embed.add_field(name="Volume", value=f"{int(source.volume*100)}%") embed.add_field(name="Volume", value=f"{int(source.volume*100)}%")
embed.add_field(name="Views", value=f"{source.view_count:,}") embed.add_field(name="Views", value=f"{source.view_count:,}")

View File

@ -3,11 +3,10 @@ import collections
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Optional from typing import Any, Optional
import constants
import disnake import disnake
import yt_dlp import yt_dlp
import constants
ytdl = yt_dlp.YoutubeDL(constants.YTDL_OPTIONS) ytdl = yt_dlp.YoutubeDL(constants.YTDL_OPTIONS)
@ -33,6 +32,7 @@ class YTDLSource(disnake.PCMVolumeTransformer):
): ):
super().__init__(source, volume) super().__init__(source, volume)
self.description = data.get("description")
self.duration = data.get("duration") self.duration = data.get("duration")
self.original_url = data.get("original_url") self.original_url = data.get("original_url")
self.thumbnail_url = data.get("thumbnail") self.thumbnail_url = data.get("thumbnail")