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
|
# Default Value: 0
|
||||||
MaxSongDuration = 0
|
MaxSongDuration = 0
|
||||||
|
|
||||||
|
# Maximum songs per playlist (0 = unrestricted)
|
||||||
|
# Default Value: 50
|
||||||
|
MaxSongPerPlaylist = 50
|
||||||
|
|
||||||
# Is playlist shuffling enabled when the bot starts?
|
# Is playlist shuffling enabled when the bot starts?
|
||||||
# Default Value: false
|
# Default Value: false
|
||||||
AutomaticShuffleOn = false
|
AutomaticShuffleOn = false
|
||||||
|
|
|
@ -22,6 +22,7 @@ type DjConfig struct {
|
||||||
PlaylistSkipRatio float32
|
PlaylistSkipRatio float32
|
||||||
DefaultComment string
|
DefaultComment string
|
||||||
MaxSongDuration int
|
MaxSongDuration int
|
||||||
|
MaxSongPerPlaylist int
|
||||||
AutomaticShuffleOn bool
|
AutomaticShuffleOn bool
|
||||||
}
|
}
|
||||||
Cache struct {
|
Cache struct {
|
||||||
|
|
|
@ -173,9 +173,17 @@ func (yt YouTube) NewPlaylist(user *gumble.User, id string) ([]Song, error) {
|
||||||
songArray = append(songArray, song)
|
songArray = append(songArray, song)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pageToken, err = apiResponse.String("nextPageToken"); err != nil{
|
if pageToken, err = apiResponse.String("nextPageToken"); err != nil || playlistSizeExceeded(songArray) {
|
||||||
morePages = false
|
morePages = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (dj.conf.General.MaxSongPerPlaylist > 0 && len(songArray) > dj.conf.General.MaxSongPerPlaylist){
|
||||||
|
songArray = songArray[:dj.conf.General.MaxSongPerPlaylist]
|
||||||
|
}
|
||||||
return songArray, nil
|
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