Skip to content
This repository has been archived by the owner on Jan 20, 2021. It is now read-only.

Commit

Permalink
Fix #11: Crash on skip when no song is playing
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieugrieger committed Jan 7, 2015
1 parent 73d5050 commit 9667157
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
MumbleDJ Changelog
==================

### January 7, 2015 -- `v2.2.3`
* Fixed a crash caused by entering a skip request when no song is currently playing.

### January 5, 2015 -- `v2.2.1, v2.2.2`
* Attached `gumbleutil.AutoBitrate` EventListener to client. This should hopefully fix the issues with audio cutting in and out.
* Moved dependency installation to default `make` command to better enforce new updates.
Expand Down
68 changes: 36 additions & 32 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,49 +179,53 @@ func add(user *gumble.User, username, url string) {
// Performs skip functionality. Adds a skip to the skippers slice for the current song, and then
// evaluates if a skip should be performed. Both skip and forceskip are implemented here.
func skip(user *gumble.User, username string, admin, playlistSkip bool) {
if playlistSkip {
if dj.queue.CurrentItem().ItemType() == "playlist" {
if err := dj.queue.CurrentItem().AddSkip(username); err == nil {
if dj.audioStream.IsPlaying() {
if playlistSkip {
if dj.queue.CurrentItem().ItemType() == "playlist" {
if err := dj.queue.CurrentItem().AddSkip(username); err == nil {
if admin {
dj.client.Self().Channel().Send(ADMIN_PLAYLIST_SKIP_MSG, false)
} else {
dj.client.Self().Channel().Send(fmt.Sprintf(PLAYLIST_SKIP_ADDED_HTML, username), false)
}
if dj.queue.CurrentItem().SkipReached(len(dj.client.Self().Channel().Users())) || admin {
dj.queue.CurrentItem().(*Playlist).skipped = true
dj.client.Self().Channel().Send(PLAYLIST_SKIPPED_HTML, false)
if err := dj.audioStream.Stop(); err != nil {
panic(errors.New("An error occurred while stopping the current song."))
}
}
} else {
panic(errors.New("An error occurred while adding a skip to the current playlist."))
}
} else {
user.Send(NO_PLAYLIST_PLAYING_MSG)
}
} else {
var currentItem QueueItem
if dj.queue.CurrentItem().ItemType() == "playlist" {
currentItem = dj.queue.CurrentItem().(*Playlist).songs.CurrentItem()
} else {
currentItem = dj.queue.CurrentItem()
}
if err := currentItem.AddSkip(username); err == nil {
if admin {
dj.client.Self().Channel().Send(ADMIN_PLAYLIST_SKIP_MSG, false)
dj.client.Self().Channel().Send(ADMIN_SONG_SKIP_MSG, false)
} else {
dj.client.Self().Channel().Send(fmt.Sprintf(PLAYLIST_SKIP_ADDED_HTML, username), false)
dj.client.Self().Channel().Send(fmt.Sprintf(SKIP_ADDED_HTML, username), false)
}
if dj.queue.CurrentItem().SkipReached(len(dj.client.Self().Channel().Users())) || admin {
dj.queue.CurrentItem().(*Playlist).skipped = true
dj.client.Self().Channel().Send(PLAYLIST_SKIPPED_HTML, false)
if currentItem.SkipReached(len(dj.client.Self().Channel().Users())) || admin {
dj.client.Self().Channel().Send(SONG_SKIPPED_HTML, false)
if err := dj.audioStream.Stop(); err != nil {
panic(errors.New("An error occurred while stopping the current song."))
}
}
} else {
panic(errors.New("An error occurred while adding a skip to the current playlist."))
panic(errors.New("An error occurred while adding a skip to the current song."))
}
} else {
user.Send(NO_PLAYLIST_PLAYING_MSG)
}
} else {
var currentItem QueueItem
if dj.queue.CurrentItem().ItemType() == "playlist" {
currentItem = dj.queue.CurrentItem().(*Playlist).songs.CurrentItem()
} else {
currentItem = dj.queue.CurrentItem()
}
if err := currentItem.AddSkip(username); err == nil {
if admin {
dj.client.Self().Channel().Send(ADMIN_SONG_SKIP_MSG, false)
} else {
dj.client.Self().Channel().Send(fmt.Sprintf(SKIP_ADDED_HTML, username), false)
}
if currentItem.SkipReached(len(dj.client.Self().Channel().Users())) || admin {
dj.client.Self().Channel().Send(SONG_SKIPPED_HTML, false)
if err := dj.audioStream.Stop(); err != nil {
panic(errors.New("An error occurred while stopping the current song."))
}
}
} else {
panic(errors.New("An error occurred while adding a skip to the current song."))
}
user.Send(NO_MUSIC_PLAYING_MSG)
}
}

Expand Down

0 comments on commit 9667157

Please sign in to comment.