Updated dependencies, updated code to reflect gumble API changes

pull/42/head
Matthieu Grieger 2015-02-11 15:25:47 -08:00
parent 16572caad9
commit 24fb620e1f
6 changed files with 36 additions and 33 deletions

View File

@ -1,6 +1,9 @@
MumbleDJ Changelog
==================
### February 11, 2015 -- `v2.4.4`
* Updated dependencies and fixed code to match `gumble` API changes.
### February 9, 2015 -- `v2.4.3`
* Added configuration option in `mumbledj.gcfg` for default bot comment.
* Fixed text messages only containing images crashing the bot.

View File

@ -1,5 +1,5 @@
github.com/layeh/gumble/gumble #313707b6f7c2699602dbd07e244ad2768d25b581
github.com/layeh/gumble/gumble_ffmpeg #ed900e422315c00121362676dd51aa0506ee18c0
github.com/layeh/gumble/gumbleutil #313707b6f7c2699602dbd07e244ad2768d25b581
github.com/layeh/gumble/gumble #7a51b66e0368f81cdddf116a9952194f3e5448f2
github.com/layeh/gumble/gumble_ffmpeg #fe938c5cbbd8123727edda2f393312ea030a02ec
github.com/layeh/gumble/gumbleutil #fe938c5cbbd8123727edda2f393312ea030a02ec
code.google.com/p/gcfg #c2d3050044d0
github.com/jmoiron/jsonq #7c27c8eb9f6831555a4209f6a7d579159e766a3c

View File

@ -171,7 +171,7 @@ func add(user *gumble.User, username, url string) {
if matchFound {
if newSong, err := NewSong(username, shortUrl); err == nil {
if err := dj.queue.AddItem(newSong); err == nil {
dj.client.Self().Channel().Send(fmt.Sprintf(SONG_ADDED_HTML, username, newSong.title), false)
dj.client.Self.Channel.Send(fmt.Sprintf(SONG_ADDED_HTML, username, newSong.title), false)
if dj.queue.Len() == 1 && !dj.audioStream.IsPlaying() {
if err := dj.queue.CurrentItem().(*Song).Download(); err == nil {
dj.queue.CurrentItem().(*Song).Play()
@ -193,7 +193,7 @@ func add(user *gumble.User, username, url string) {
shortUrl = re.FindStringSubmatch(url)[1]
if newPlaylist, err := NewPlaylist(username, shortUrl); err == nil {
if dj.queue.AddItem(newPlaylist); err == nil {
dj.client.Self().Channel().Send(fmt.Sprintf(PLAYLIST_ADDED_HTML, username, newPlaylist.title), false)
dj.client.Self.Channel.Send(fmt.Sprintf(PLAYLIST_ADDED_HTML, username, newPlaylist.title), false)
if dj.queue.Len() == 1 && !dj.audioStream.IsPlaying() {
if err := dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Download(); err == nil {
dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Play()
@ -225,13 +225,13 @@ func skip(user *gumble.User, username string, admin, playlistSkip bool) {
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)
dj.client.Self.Channel.Send(ADMIN_PLAYLIST_SKIP_MSG, false)
} else {
dj.client.Self().Channel().Send(fmt.Sprintf(PLAYLIST_SKIP_ADDED_HTML, username), false)
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 {
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)
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."))
}
@ -249,12 +249,12 @@ func skip(user *gumble.User, username string, admin, playlistSkip bool) {
}
if err := currentItem.AddSkip(username); err == nil {
if admin {
dj.client.Self().Channel().Send(ADMIN_SONG_SKIP_MSG, false)
dj.client.Self.Channel.Send(ADMIN_SONG_SKIP_MSG, false)
} else {
dj.client.Self().Channel().Send(fmt.Sprintf(SKIP_ADDED_HTML, username), false)
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 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."))
}
@ -276,13 +276,13 @@ func help(user *gumble.User) {
// is applied and is immediately in effect.
func volume(user *gumble.User, username, value string) {
if value == "" {
dj.client.Self().Channel().Send(fmt.Sprintf(CUR_VOLUME_HTML, dj.audioStream.Volume), false)
dj.client.Self.Channel.Send(fmt.Sprintf(CUR_VOLUME_HTML, dj.audioStream.Volume), false)
} else {
if parsedVolume, err := strconv.ParseFloat(value, 32); err == nil {
newVolume := float32(parsedVolume)
if newVolume >= dj.conf.Volume.LowestVolume && newVolume <= dj.conf.Volume.HighestVolume {
dj.audioStream.Volume = newVolume
dj.client.Self().Channel().Send(fmt.Sprintf(VOLUME_SUCCESS_HTML, username, dj.audioStream.Volume), false)
dj.client.Self.Channel.Send(fmt.Sprintf(VOLUME_SUCCESS_HTML, username, dj.audioStream.Volume), false)
} else {
dj.SendPrivateMessage(user, fmt.Sprintf(NOT_IN_VOLUME_RANGE_MSG, dj.conf.Volume.LowestVolume, dj.conf.Volume.HighestVolume))
}
@ -298,8 +298,8 @@ func move(user *gumble.User, channel string) {
if channel == "" {
dj.SendPrivateMessage(user, NO_ARGUMENT_MSG)
} else {
if dj.client.Channels().Find(channel) != nil {
dj.client.Self().Move(dj.client.Channels().Find(channel))
if dj.client.Channels.Find(channel) != nil {
dj.client.Self.Move(dj.client.Channels.Find(channel))
} else {
dj.SendPrivateMessage(user, CHANNEL_DOES_NOT_EXIST_MSG)
}
@ -323,7 +323,7 @@ func reset(username string) {
}
}
if err := deleteSongs(); err == nil {
dj.client.Self().Channel().Send(fmt.Sprintf(QUEUE_RESET_HTML, username), false)
dj.client.Self.Channel.Send(fmt.Sprintf(QUEUE_RESET_HTML, username), false)
} else {
panic(err)
}
@ -337,7 +337,7 @@ func numSongs() {
dj.queue.Traverse(func(i int, item QueueItem) {
songCount += 1
})
dj.client.Self().Channel().Send(fmt.Sprintf(NUM_SONGS_HTML, songCount), false)
dj.client.Self.Channel.Send(fmt.Sprintf(NUM_SONGS_HTML, songCount), false)
}
// Performs nextsong functionality. Uses the SongQueue PeekNext function to peek at the next
@ -374,7 +374,7 @@ func currentSong(user *gumble.User) {
// Performs setcomment functionality. Sets the bot's comment to whatever text is supplied in the argument.
func setComment(user *gumble.User, comment string) {
dj.client.Self().SetComment(comment)
dj.client.Self.SetComment(comment)
dj.SendPrivateMessage(user, COMMENT_UPDATED_MSG)
}

18
main.go
View File

@ -35,8 +35,8 @@ type mumbledj struct {
// via commandline args, and moves to root channel if the channel does not exist. The current
// user's homedir path is stored, configuration is loaded, and the audio stream is set up.
func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
if dj.client.Channels().Find(dj.defaultChannel) != nil {
dj.client.Self().Move(dj.client.Channels().Find(dj.defaultChannel))
if dj.client.Channels.Find(dj.defaultChannel) != nil {
dj.client.Self.Move(dj.client.Channels.Find(dj.defaultChannel))
} else {
fmt.Println("Channel doesn't exist or one was not provided, staying in root channel...")
}
@ -58,9 +58,9 @@ func (dj *mumbledj) OnConnect(e *gumble.ConnectEvent) {
panic(err)
}
dj.client.AudioEncoder().SetApplication(gopus.Audio)
dj.client.AudioEncoder.SetApplication(gopus.Audio)
dj.client.Self().SetComment(dj.conf.General.DefaultComment)
dj.client.Self.SetComment(dj.conf.General.DefaultComment)
}
// OnDisconnect event. Terminates MumbleDJ thread.
@ -74,7 +74,7 @@ func (dj *mumbledj) OnTextMessage(e *gumble.TextMessageEvent) {
plainMessage := gumbleutil.PlainText(&e.TextMessage)
if len(plainMessage) != 0 {
if plainMessage[0] == dj.conf.General.CommandPrefix[0] && plainMessage != dj.conf.General.CommandPrefix {
parseCommand(e.Sender, e.Sender.Name(), plainMessage[1:])
parseCommand(e.Sender, e.Sender.Name, plainMessage[1:])
}
}
}
@ -85,10 +85,10 @@ func (dj *mumbledj) OnUserChange(e *gumble.UserChangeEvent) {
if e.Type.Has(gumble.UserChangeDisconnected) {
if dj.audioStream.IsPlaying() {
if dj.queue.CurrentItem().ItemType() == "playlist" {
dj.queue.CurrentItem().(*Playlist).RemoveSkip(e.User.Name())
dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).RemoveSkip(e.User.Name())
dj.queue.CurrentItem().(*Playlist).RemoveSkip(e.User.Name)
dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).RemoveSkip(e.User.Name)
} else {
dj.queue.CurrentItem().(*Song).RemoveSkip(e.User.Name())
dj.queue.CurrentItem().(*Song).RemoveSkip(e.User.Name)
}
}
}
@ -112,7 +112,7 @@ func (dj *mumbledj) HasPermission(username string, command bool) bool {
// Sends a private message to a user. Essentially just checks if a user is still in the server
// before sending them the message.
func (dj *mumbledj) SendPrivateMessage(user *gumble.User, message string) {
if targetUser := dj.client.Self().Channel().Users().Find(user.Name()); targetUser != nil {
if targetUser := dj.client.Self.Channel.Users.Find(user.Name); targetUser != nil {
targetUser.Send(message)
}
}

View File

@ -91,10 +91,10 @@ func (s *Song) Play() {
panic(err)
} else {
if s.playlistTitle == "" {
dj.client.Self().Channel().Send(fmt.Sprintf(NOW_PLAYING_HTML, s.thumbnailUrl, s.youtubeId, s.title,
dj.client.Self.Channel.Send(fmt.Sprintf(NOW_PLAYING_HTML, s.thumbnailUrl, s.youtubeId, s.title,
s.duration, s.submitter), false)
} else {
dj.client.Self().Channel().Send(fmt.Sprintf(NOW_PLAYING_PLAYLIST_HTML, s.thumbnailUrl, s.youtubeId,
dj.client.Self.Channel.Send(fmt.Sprintf(NOW_PLAYING_PLAYLIST_HTML, s.thumbnailUrl, s.youtubeId,
s.title, s.duration, s.submitter, s.playlistTitle), false)
}
}

View File

@ -139,14 +139,14 @@ func (q *SongQueue) PrepareAndPlayNextItem() {
if err := q.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Download(); err == nil {
q.CurrentItem().(*Playlist).songs.CurrentItem().(*Song).Play()
} else {
dj.client.Self().Channel().Send(AUDIO_FAIL_MSG, false)
dj.client.Self.Channel.Send(AUDIO_FAIL_MSG, false)
q.OnItemFinished()
}
} else {
if err := q.CurrentItem().(*Song).Download(); err == nil {
q.CurrentItem().(*Song).Play()
} else {
dj.client.Self().Channel().Send(AUDIO_FAIL_MSG, false)
dj.client.Self.Channel.Send(AUDIO_FAIL_MSG, false)
q.OnItemFinished()
}
}