From 0275ab2fb3b006ce474564b06a8dff93b0ad3275 Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Mon, 2 Feb 2015 11:41:11 -0800 Subject: [PATCH] Fix https://github.com/matthieugrieger/mumbledj/issues/32: \!reset crash when no audio is playing --- CHANGELOG.md | 1 + commands.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf52f0f..0f443d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ MumbleDJ Changelog ### February 2, 2015 -- `v2.3.4, v2.3.5` * Added panic on audio play fail for debugging purposes. * Fixed '!' being recognized as '!skipplaylist'. +* Fixed !reset crash when there is no audio playing. ### January 30, 2015 -- `v2.3.3` * Fixed private messages crashing the bot when the target user switches channels or disconnects. diff --git a/commands.go b/commands.go index 31b50ee..ec4402a 100644 --- a/commands.go +++ b/commands.go @@ -304,12 +304,13 @@ func reload(user *gumble.User) { // remaining songs in the ~/.mumbledj/songs directory. func reset(username string) { dj.queue.queue = dj.queue.queue[:0] - if err := dj.audioStream.Stop(); err == nil { - if err := deleteSongs(); err == nil { - dj.client.Self().Channel().Send(fmt.Sprintf(QUEUE_RESET_HTML, username), false) - } else { + if dj.audioStream.IsPlaying() { + if err := dj.audioStream.Stop(); err != nil { panic(err) } + } + if err := deleteSongs(); err == nil { + dj.client.Self().Channel().Send(fmt.Sprintf(QUEUE_RESET_HTML, username), false) } else { panic(err) }