diff --git a/CHANGELOG.md b/CHANGELOG.md index 37473e7..634d1b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ MumbleDJ Changelog ================== +### February 18, 2015 -- `v2.6.2` +* Fixed bot crashing after 5 minutes if there is nothing in the song queue. + ### February 17, 2015 -- `v2.6.0, v2.6.1` * Added caching system to MumbleDJ. * Added configuration variables in `mumbledj.gcfg` for caching related settings (please note that caching is off by default). diff --git a/cache.go b/cache.go index f85ab16..d05149c 100644 --- a/cache.go +++ b/cache.go @@ -73,8 +73,14 @@ func (c *SongCache) ClearExpired() { songs, _ := ioutil.ReadDir(fmt.Sprintf("%s/.mumbledj/songs", dj.homeDir)) for _, song := range songs { hours := time.Since(song.ModTime()).Hours() - if hours >= dj.conf.Cache.ExpireTime && (dj.queue.CurrentSong().youtubeId+".m4a") != song.Name() { - os.Remove(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, song.Name())) + if hours >= dj.conf.Cache.ExpireTime { + if dj.queue.Len() > 0 { + if (dj.queue.CurrentSong().youtubeId + ".m4a") != song.Name() { + os.Remove(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, song.Name())) + } + } else { + os.Remove(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, song.Name())) + } } } } @@ -83,9 +89,13 @@ func (c *SongCache) ClearExpired() { func (c *SongCache) ClearOldest() error { songs, _ := ioutil.ReadDir(fmt.Sprintf("%s/.mumbledj/songs", dj.homeDir)) sort.Sort(ByAge(songs)) - if (dj.queue.CurrentSong().youtubeId + ".m4a") != songs[0].Name() { - return os.Remove(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, songs[0].Name())) + if dj.queue.Len() > 0 { + if (dj.queue.CurrentSong().youtubeId + ".m4a") != songs[0].Name() { + return os.Remove(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, songs[0].Name())) + } else { + return errors.New("Song is currently playing.") + } } else { - return errors.New("Song is currently playing.") + return os.Remove(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, songs[0].Name())) } }