mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 23:37:47 +00:00
Added history support and changed track fmting
This commit is contained in:
+18
-35
@@ -6,35 +6,24 @@ 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})"
|
||||
try:
|
||||
duration = str(datetime.timedelta(milliseconds=int(track.duration)))
|
||||
except OverflowError:
|
||||
duration = "0:00:00"
|
||||
|
||||
if max_length == 0:
|
||||
return f"`{duration}` [{track.title}]({track.uri})"
|
||||
|
||||
max_length -= len(duration) + 1
|
||||
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))
|
||||
return f"`{duration}` [{track_title}]({track.uri})"
|
||||
|
||||
|
||||
def create_track_embed(
|
||||
@@ -47,25 +36,19 @@ def create_track_embed(
|
||||
colour=colors["embed"],
|
||||
)
|
||||
|
||||
try:
|
||||
duration = str(datetime.timedelta(milliseconds=int(current.duration)))
|
||||
except OverflowError:
|
||||
duration = "🔴 LIVE"
|
||||
|
||||
embed.description = f"`{duration}` [{current.title}]({current.uri})"
|
||||
embed.description = format_track(current)
|
||||
|
||||
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)
|
||||
upcoming_fmt = "\n".join(format_track(track) for track in queue)
|
||||
else:
|
||||
upcoming_fmt = "No tracks have been queued yet..."
|
||||
embed.add_field(name="Upcoming", value=upcoming_fmt)
|
||||
embed.add_field(name="Coming up", value=upcoming_fmt, inline=False)
|
||||
|
||||
if len(history) > 0:
|
||||
history_fmt = "\n".join(format_track(track) for track in history)
|
||||
else:
|
||||
history_fmt = "No history yet..."
|
||||
embed.add_field(name="Previously played", value=history_fmt, inline=False)
|
||||
|
||||
embed.set_image(url=f"https://i3.ytimg.com/vi/{current.identifier}/mqdefault.jpg")
|
||||
embed.set_footer(text=f"Uploaded by: {current.author}")
|
||||
|
||||
Reference in New Issue
Block a user