Skip to content

Commit

Permalink
feat: add loop info in current progression
Browse files Browse the repository at this point in the history
  • Loading branch information
Dysta committed Sep 19, 2024
1 parent fbc3062 commit c0b7272
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jukebot/services/music/current_song_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def __call__(self, /, interaction: CommandInteraction):
stream: AudioStream = player.stream
song: Song = player.song
if stream and song:
e = embed.music_message(song, stream.progress)
e = embed.music_message(song, player.loop, stream.progress)
else:
e = embed.basic_message(title="Nothing is currently playing", content=f"Try `/play` to add a music !")
await interaction.send(embed=e)
2 changes: 1 addition & 1 deletion jukebot/services/music/play_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def __call__(
logger.opt(lazy=True).success(
f"Server {interaction.guild.name} ({interaction.guild.id}) can play in its player."
)
e: Embed = embed.music_message(song)
e: Embed = embed.music_message(song, player.loop)
await interaction.edit_original_message(embed=e)
return True

Expand Down
18 changes: 13 additions & 5 deletions jukebot/utils/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

if TYPE_CHECKING:
from jukebot.components import Result, ResultSet, Song
from jukebot.components.player import Player

VOID_TOKEN = "\u200B"

Expand Down Expand Up @@ -58,7 +59,7 @@ def activity_message(title="", content=""):
return embed


def music_message(song: Song, current_duration: int = 0):
def music_message(song: Song, loop_mode: Player.Loop, current_duration: int = 0):
colors = [0x736DAB, 0xFFBA58]
c = colors[random.randint(0, 1)]

Expand All @@ -68,15 +69,22 @@ def music_message(song: Song, current_duration: int = 0):
url=song.web_url,
icon_url="https://icons.iconarchive.com/icons/papirus-team/papirus-apps/512/musicbrainz-icon.png",
)
embed.add_field(name="Channel", value=song.channel, inline=bool(len(song.title) >= 40))

if song.thumbnail:
embed.set_thumbnail(url=song.thumbnail)

embed.add_field(name="Channel", value=song.channel, inline=True)
if current_duration:
embed.add_field(VOID_TOKEN, VOID_TOKEN, inline=True)
embed.add_field("Loop", loop_mode.name.capitalize(), inline=True)

if current_duration:
line = converter.duration_seconds_to_progress_bar(current_duration, song.duration)
fmt_current: str = converter.seconds_to_youtube_format(current_duration)
embed.add_field(name="Progression", value=f"`{fmt_current} {line} {song.fmt_duration}`")
else:
embed.add_field(name="Duration", value=song.fmt_duration)
if song.thumbnail:
embed.set_thumbnail(url=song.thumbnail)
embed.add_field(name="Duration", value=f"`{song.fmt_duration}`")

return embed


Expand Down

0 comments on commit c0b7272

Please sign in to comment.