diff --git a/commands.go b/commands.go index 8ff8846..488f17e 100644 --- a/commands.go +++ b/commands.go @@ -8,6 +8,7 @@ package main import ( + "bytes" "errors" "fmt" "os" @@ -162,14 +163,14 @@ func parseCommand(user *gumble.User, username, command string) { } // Shuffleon command - case dj.conf.Aliases.ShuffleOnAlias: + case dj.conf.Aliases.ShuffleOnAlias: if dj.HasPermission(username, dj.conf.Permissions.AdminShuffleToggle) { toggleAutomaticShuffle(true, user, username) } else { dj.SendPrivateMessage(user, NO_PERMISSION_MSG) } - // Shuffleoff command + // Shuffleoff command case dj.conf.Aliases.ShuffleOffAlias: if dj.HasPermission(username, dj.conf.Permissions.AdminShuffleToggle) { toggleAutomaticShuffle(false, user, username) @@ -177,6 +178,13 @@ func parseCommand(user *gumble.User, username, command string) { dj.SendPrivateMessage(user, NO_PERMISSION_MSG) } + // ListSongs command + case dj.conf.Aliases.ListSongsAlias: + if dj.HasPermission(username, dj.conf.Permissions.AdminListSongs) { + listSongs(user) + } else { + dj.SendPrivateMessage(user, NO_PERMISSION_MSG) + } default: dj.SendPrivateMessage(user, COMMAND_DOESNT_EXIST_MSG) } @@ -428,17 +436,30 @@ func shuffleSongs(user *gumble.User, username string) { } // handles toggling of automatic shuffle playing -func toggleAutomaticShuffle(activate bool, user *gumble.User, username string){ - if (dj.conf.General.AutomaticShuffleOn != activate){ +func toggleAutomaticShuffle(activate bool, user *gumble.User, username string) { + if dj.conf.General.AutomaticShuffleOn != activate { dj.conf.General.AutomaticShuffleOn = activate - if (activate){ + if activate { dj.client.Self.Channel.Send(fmt.Sprintf(SHUFFLE_ON_MESSAGE, username), false) - } else{ + } else { dj.client.Self.Channel.Send(fmt.Sprintf(SHUFFLE_OFF_MESSAGE, username), false) } - } else if (activate){ + } else if activate { dj.SendPrivateMessage(user, SHUFFLE_ACTIVATED_ERROR_MESSAGE) - } else{ + } else { dj.SendPrivateMessage(user, SHUFFLE_DEACTIVATED_ERROR_MESSAGE) } } + +// listSongs handles !listSongs functionality. Sends a private message to the user a list of all songs in the queue +func listSongs(user *gumble.User) { + if dj.audioStream.IsPlaying() { + var buffer bytes.Buffer + dj.queue.Traverse(func(i int, song Song) { + buffer.WriteString(fmt.Sprintf(SONG_LIST_HTML, song.Title(), song.Submitter())) + }) + dj.SendPrivateMessage(user, buffer.String()) + } else { + dj.SendPrivateMessage(user, NO_MUSIC_PLAYING_MSG) + } +} diff --git a/config.gcfg b/config.gcfg index f9c81fa..9ac089b 100644 --- a/config.gcfg +++ b/config.gcfg @@ -146,6 +146,10 @@ ShuffleOnAlias = "shuffleon" # DEFAULT VALUE: "shuffleoff" ShuffleOffAlias = "shuffleoff" +# Alias used for listsongs command +# DEFAULT_VALUE: "listsongs" +ListSongsAlias = "listsongs" + [Permissions] # Enable admins @@ -225,6 +229,9 @@ AdminKill = true # DEFAULT VALUE: true AdminShuffle = true +# Make listSongs an admin command? +# DEFAULT VALUE: false +AdminListSongs = false # Make shuffleon and shuffleoff admin commands? # DEFAULT VALUE: true diff --git a/main.go b/main.go index 553c500..7f4d469 100644 --- a/main.go +++ b/main.go @@ -136,7 +136,6 @@ func CheckAPIKeys() { anyDisabled := false // Checks YouTube API key - if dj.conf.ServiceKeys.Youtube == "" { anyDisabled = true fmt.Printf("The youtube service has been disabled as you do not have a YouTube API key defined in your config file!\n") @@ -230,9 +229,9 @@ func main() { } dj.defaultChannel = strings.Split(channel, "/") - + CheckAPIKeys() - + dj.client.Attach(gumbleutil.Listener{ Connect: dj.OnConnect, Disconnect: dj.OnDisconnect, diff --git a/parseconfig.go b/parseconfig.go index e09d460..715fed3 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -17,13 +17,13 @@ import ( // DjConfig is a Golang struct representation of mumbledj.gcfg file structure for parsing. type DjConfig struct { General struct { - CommandPrefix string - SkipRatio float32 - PlaylistSkipRatio float32 - DefaultComment string - MaxSongDuration int - MaxSongPerPlaylist int - AutomaticShuffleOn bool + CommandPrefix string + SkipRatio float32 + PlaylistSkipRatio float32 + DefaultComment string + MaxSongDuration int + MaxSongPerPlaylist int + AutomaticShuffleOn bool } Cache struct { Enabled bool @@ -56,31 +56,33 @@ type DjConfig struct { ShuffleAlias string ShuffleOnAlias string ShuffleOffAlias string + ListSongsAlias string } Permissions struct { - AdminsEnabled bool - Admins []string - AdminAdd bool - AdminAddPlaylists bool - AdminSkip bool - AdminHelp bool - AdminVolume bool - AdminMove bool - AdminReload bool - AdminReset bool - AdminNumSongs bool - AdminNextSong bool - AdminCurrentSong bool - AdminSetComment bool - AdminNumCached bool - AdminCacheSize bool - AdminKill bool - AdminShuffle bool - AdminShuffleToggle bool + AdminsEnabled bool + Admins []string + AdminAdd bool + AdminAddPlaylists bool + AdminSkip bool + AdminHelp bool + AdminVolume bool + AdminMove bool + AdminReload bool + AdminReset bool + AdminNumSongs bool + AdminNextSong bool + AdminCurrentSong bool + AdminSetComment bool + AdminNumCached bool + AdminCacheSize bool + AdminKill bool + AdminShuffle bool + AdminShuffleToggle bool + AdminListSongs bool } ServiceKeys struct { - Youtube string - SoundCloud string + Youtube string + SoundCloud string } } diff --git a/strings.go b/strings.go index 8e19199..12e7f0d 100644 --- a/strings.go +++ b/strings.go @@ -118,6 +118,7 @@ const HELP_HTML = `

!skip - Casts a vote to skip the current song

!skipplaylist - Casts a vote to skip over the current playlist.

!numsongs - Shows how many songs are in queue.

+

!listsongs - Lists the songs in queue.

!nextsong - Shows the title and submitter of the next queue item if it exists.

!currentsong - Shows the title and submitter of the song currently playing.


@@ -191,3 +192,6 @@ const CURRENT_SONG_HTML = ` const CURRENT_SONG_PLAYLIST_HTML = ` The %s currently playing is "%s", added %s from the %s "%s". ` +const SONG_LIST_HTML = ` +
"%s", added by %s +`