support maximum songs per playlist config
This commit is contained in:
parent
411cbadb59
commit
6ef13568fa
|
@ -26,6 +26,10 @@ DefaultComment = "Hello! I am a bot. Type !help for a list of commands."
|
|||
# Default Value: 0
|
||||
MaxSongDuration = 0
|
||||
|
||||
# Maximum songs per playlist (0 = unrestricted)
|
||||
# Default Value: 50
|
||||
MaxSongPerPlaylist = 50
|
||||
|
||||
# Is playlist shuffling enabled when the bot starts?
|
||||
# Default Value: false
|
||||
AutomaticShuffleOn = false
|
||||
|
|
|
@ -22,6 +22,7 @@ type DjConfig struct {
|
|||
PlaylistSkipRatio float32
|
||||
DefaultComment string
|
||||
MaxSongDuration int
|
||||
MaxSongPerPlaylist int
|
||||
AutomaticShuffleOn bool
|
||||
}
|
||||
Cache struct {
|
||||
|
|
|
@ -173,9 +173,17 @@ func (yt YouTube) NewPlaylist(user *gumble.User, id string) ([]Song, error) {
|
|||
songArray = append(songArray, song)
|
||||
}
|
||||
}
|
||||
if pageToken, err = apiResponse.String("nextPageToken"); err != nil{
|
||||
if pageToken, err = apiResponse.String("nextPageToken"); err != nil || playlistSizeExceeded(songArray) {
|
||||
morePages = false
|
||||
}
|
||||
}
|
||||
if (dj.conf.General.MaxSongPerPlaylist > 0 && len(songArray) > dj.conf.General.MaxSongPerPlaylist){
|
||||
songArray = songArray[:dj.conf.General.MaxSongPerPlaylist]
|
||||
}
|
||||
return songArray, nil
|
||||
}
|
||||
|
||||
// checks if the number of songs of the playlist exceeds the configured playlist maximum size
|
||||
func playlistSizeExceeded(songs []Song) bool{
|
||||
return dj.conf.General.MaxSongPerPlaylist > 0 && len(songs) > dj.conf.General.MaxSongPerPlaylist
|
||||
}
|
||||
|
|
Reference in a new issue