Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev-new-structure'
Browse files Browse the repository at this point in the history
  • Loading branch information
keshon committed Dec 12, 2023
2 parents 088e552 + 81b7cc2 commit 2817e55
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 44 deletions.
86 changes: 44 additions & 42 deletions music/discord/cmd_play.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,20 @@ func enqueuePlaylistV2(d *Discord, playlist []*player.Song, s *discordgo.Session
}

// Update playlist message
if err := updatePlaylistMessage(s, m.Message.ChannelID, prevMessageID, playlist, previousPlaylistExist); err != nil {
if err := updateAddToQueueMessage(s, m.Message.ChannelID, prevMessageID, playlist, previousPlaylistExist); err != nil {
return err
}

// Start playing if not in enqueue-only mode
if !enqueueOnly && d.Player.GetCurrentStatus() != player.StatusPlaying {
go updatePlayingStatus(d, s, m.Message.ChannelID, prevMessageID, playlist, previousPlaylistExist)
go updatePlayingNowMessage(d, s, m.Message.ChannelID, prevMessageID, playlist, previousPlaylistExist)
d.Player.Play(0, nil)
}

return nil
}

func updatePlaylistMessage(s *discordgo.Session, channelID, prevMessageID string, playlist []*player.Song, previousPlaylistExist int) error {
func updateAddToQueueMessage(s *discordgo.Session, channelID, prevMessageID string, playlist []*player.Song, previousPlaylistExist int) error {
embedMsg := embed.NewEmbed().
SetColor(0x9f00d4).
SetFooter(version.AppFullName)
Expand All @@ -206,11 +206,14 @@ func updatePlaylistMessage(s *discordgo.Session, channelID, prevMessageID string
}
break
} else if i == len(playlist)-1 {
playlistContent = fmt.Sprintf("%v\n` %v ` [%v](%v)", playlistContent, i, song.Name, song.UserURL)
if previousPlaylistExist > 0 {
playlistContent = fmt.Sprintf("%v\n\n Some tracks have already been added — `!list` to see", playlistContent)
}
} else {
playlistContent = fmt.Sprintf("%v\n` %v ` [%v](%v)", playlistContent, i, song.Name, song.UserURL)
}
playlistContent = fmt.Sprintf("%v\n` %v ` [%v](%v)", playlistContent, i, song.Name, song.UserURL)

}

embedMsg.SetDescription(playlistContent)
Expand All @@ -224,7 +227,7 @@ func updatePlaylistMessage(s *discordgo.Session, channelID, prevMessageID string
return nil
}

func updatePlayingStatus(d *Discord, s *discordgo.Session, channelID, prevMessageID string, playlist []*player.Song, previousPlaylistExist int) {
func updatePlayingNowMessage(d *Discord, s *discordgo.Session, channelID, prevMessageID string, playlist []*player.Song, previousPlaylistExist int) {
for {

// Check if the player is in the playing status
Expand All @@ -234,54 +237,53 @@ func updatePlayingStatus(d *Discord, s *discordgo.Session, channelID, prevMessag
SetFooter(version.AppFullName)

statusTitle := fmt.Sprintf("%v %v", d.Player.GetCurrentStatus().StringEmoji(), d.Player.GetCurrentStatus().String())
slog.Info(statusTitle)
nextTitle := "📑 In queue"
var playlistContent string

if d.Player.GetCurrentSong() != nil {
playlistContent = statusTitle + "\n"
playlistContent = fmt.Sprintf("%v\n*[%v](%v)*\n\n", playlistContent, d.Player.GetCurrentSong().Name, d.Player.GetCurrentSong().UserURL)
embedMsg.SetThumbnail(d.Player.GetCurrentSong().Thumbnail.URL)
}
// if d.Player.GetCurrentSong() != nil {
playlistContent = statusTitle + "\n"
playlistContent = fmt.Sprintf("%v\n*[%v](%v)*\n\n", playlistContent, d.Player.GetCurrentSong().Name, d.Player.GetCurrentSong().UserURL)
embedMsg.SetThumbnail(d.Player.GetCurrentSong().Thumbnail.URL)
// }

if len(playlist) == 1 {
return
}
if len(playlist) > 1 {
playlistContent += nextTitle + "\n"

playlistContent += nextTitle + "\n"
// Separate counter variable starting from 1
counter := 1

// Separate counter variable starting from 1
counter := 1

for i, song := range playlist {
if i == 0 {
if song == d.Player.GetCurrentSong() {
// Skip the first song if it's already playing
continue
for i, song := range playlist {
if i == 0 {
if song == d.Player.GetCurrentSong() {
// Skip the first song if it's already playing
continue
}
}
}

if len(playlistContent) > 1800 {
playlistContent = fmt.Sprintf("%v\n\nList too long to fit..", playlistContent)

breakline := "\n"
if previousPlaylistExist == 0 {
breakline = "\n\n"
}
if previousPlaylistExist > 0 {
playlistContent = fmt.Sprintf("%v%v Some tracks have already been added — `%vlist` to see", playlistContent, breakline, d.prefix)
}
break
} else if i == len(playlist)-1 {
if previousPlaylistExist > 0 {
playlistContent = fmt.Sprintf("%v\n\n Some tracks have already been added — `%vlist` to see", playlistContent, d.prefix)
if len(playlistContent) > 1800 {
playlistContent = fmt.Sprintf("%v\n\nList too long to fit..", playlistContent)

breakline := "\n"
if previousPlaylistExist == 0 {
breakline = "\n\n"
}
if previousPlaylistExist > 0 {
playlistContent = fmt.Sprintf("%v%v Some tracks have already been added — `%vlist` to see", playlistContent, breakline, d.prefix)
}
break
} else if i == len(playlist)-1 {
if previousPlaylistExist > 0 {
playlistContent = fmt.Sprintf("%v\n\n Some tracks have already been added — `%vlist` to see", playlistContent, d.prefix)
}
}
}

// Use the separate counter variable for display
playlistContent = fmt.Sprintf("%v\n` %v ` [%v](%v)", playlistContent, counter, song.Name, song.UserURL)
// Use the separate counter variable for display
playlistContent = fmt.Sprintf("%v\n` %v ` [%v](%v)", playlistContent, counter, song.Name, song.UserURL)

// Increment the counter for each iteration
counter++
// Increment the counter for each iteration
counter++
}
}

embedMsg.SetDescription(playlistContent)
Expand Down
4 changes: 2 additions & 2 deletions music/discord/cmd_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func (d *Discord) handleShowQueueCommand(s *discordgo.Session, m *discordgo.Mess

if d.Player.GetCurrentStatus() != player.StatusPlaying {
// Update playlist message
if err := updatePlaylistMessage(s, m.Message.ChannelID, pleaseWaitMessage.ID, playlist, 0); err != nil {
if err := updateAddToQueueMessage(s, m.Message.ChannelID, pleaseWaitMessage.ID, playlist, 0); err != nil {
slog.Warnf("Error publishing playlist: %v", err)
}
} else {
// Start playing if not in enqueue-only mode
go updatePlayingStatus(d, s, m.Message.ChannelID, pleaseWaitMessage.ID, playlist, 0)
go updatePlayingNowMessage(d, s, m.Message.ChannelID, pleaseWaitMessage.ID, playlist, 0)

}
}

0 comments on commit 2817e55

Please sign in to comment.