Fix https://github.com/matthieugrieger/mumbledj/issues/45: Bot crashing after 5 minutes with no songs in queue

This commit is contained in:
Matthieu Grieger 2015-02-18 15:09:06 -08:00
parent 879af4798f
commit 873748bef3
2 changed files with 18 additions and 5 deletions

View file

@ -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).

View file

@ -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()))
}
}