mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 23:37:47 +00:00
New embed with queue and image
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import datetime
|
||||
import typing
|
||||
import discord
|
||||
from bot import colors
|
||||
from cogs.music import helper
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from lavalink.models import AudioTrack
|
||||
from bot import TuneBot
|
||||
|
||||
|
||||
def format_track(track: "AudioTrack", max_length: int = 0):
|
||||
if max_length == 0:
|
||||
return f"[{track.title}]({track.uri})"
|
||||
|
||||
if len(track.title) > max_length:
|
||||
track_title = track.title[: max_length - 3] + "..."
|
||||
else:
|
||||
track_title = track.title
|
||||
|
||||
return f"[{track_title}]({track.uri})"
|
||||
|
||||
|
||||
def num_to_emoji(num: int) -> str:
|
||||
emojis = {
|
||||
"1": "1️⃣",
|
||||
"2": "2️⃣",
|
||||
"3": "3️⃣",
|
||||
"4": "4️⃣",
|
||||
"5": "5️⃣",
|
||||
"6": "6️⃣",
|
||||
"7": "7️⃣",
|
||||
"8": "8️⃣",
|
||||
"9": "9️⃣",
|
||||
"0": "0️⃣",
|
||||
}
|
||||
return "".join(emojis[digit] for digit in str(num))
|
||||
|
||||
|
||||
def create_track_embed(
|
||||
current: "AudioTrack",
|
||||
queue: typing.Sequence["AudioTrack"],
|
||||
history: typing.Sequence["AudioTrack"],
|
||||
) -> discord.Embed:
|
||||
embed = discord.Embed(
|
||||
title="Now playing...",
|
||||
colour=colors["embed"],
|
||||
)
|
||||
|
||||
try:
|
||||
duration = str(datetime.timedelta(milliseconds=int(current.duration)))
|
||||
except OverflowError:
|
||||
duration = "🔴 LIVE"
|
||||
|
||||
embed.description = f"`{duration}` [{current.title}]({current.uri})"
|
||||
|
||||
if len(queue) > 0:
|
||||
frags: typing.List[str] = []
|
||||
for index, track in enumerate(queue, start=1):
|
||||
prefix = num_to_emoji(index)
|
||||
max_track_len = 45 - len(prefix)
|
||||
|
||||
track_fmt = format_track(track, max_length=max_track_len)
|
||||
frags.append(f"{prefix} {track_fmt}")
|
||||
upcoming_fmt = "\n".join(frags)
|
||||
else:
|
||||
upcoming_fmt = "No tracks have been queued yet..."
|
||||
embed.add_field(name="Upcoming", value=upcoming_fmt)
|
||||
|
||||
embed.set_image(url=f"https://i3.ytimg.com/vi/{current.identifier}/mqdefault.jpg")
|
||||
embed.set_footer(text=f"Uploaded by: {current.author}")
|
||||
return embed
|
||||
|
||||
|
||||
def create_embed_controls(bot: "TuneBot") -> "EmbedControls":
|
||||
return EmbedControls(bot)
|
||||
|
||||
|
||||
class EmbedControls(discord.ui.View):
|
||||
def __init__(self, bot: "TuneBot"):
|
||||
super().__init__()
|
||||
self.bot = bot
|
||||
|
||||
@discord.ui.button(label="Skip")
|
||||
async def skip(self, ctx: discord.Interaction, button: discord.ui.Button):
|
||||
player = helper.get_player(ctx.client, ctx.guild_id)
|
||||
await player.skip()
|
||||
await ctx.response.defer()
|
||||
Reference in New Issue
Block a user