Merge pull request #104 from nkhoit/master

Added listsongs command
This commit is contained in:
Matthieu Grieger 2015-12-14 13:01:06 -08:00
commit 7b9086c0f7
5 changed files with 72 additions and 39 deletions

View file

@ -8,6 +8,7 @@
package main
import (
"bytes"
"errors"
"fmt"
"os"
@ -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)
}
}

View file

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

View file

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

View file

@ -56,6 +56,7 @@ type DjConfig struct {
ShuffleAlias string
ShuffleOnAlias string
ShuffleOffAlias string
ListSongsAlias string
}
Permissions struct {
AdminsEnabled bool
@ -77,6 +78,7 @@ type DjConfig struct {
AdminKill bool
AdminShuffle bool
AdminShuffleToggle bool
AdminListSongs bool
}
ServiceKeys struct {
Youtube string

View file

@ -118,6 +118,7 @@ const HELP_HTML = `<br/>
<p><b>!skip</b> - Casts a vote to skip the current song</p>
<p> <b>!skipplaylist</b> - Casts a vote to skip over the current playlist.</p>
<p><b>!numsongs</b> - Shows how many songs are in queue.</p>
<p><b>!listsongs</b> - Lists the songs in queue.</p>
<p><b>!nextsong</b> - Shows the title and submitter of the next queue item if it exists.</p>
<p><b>!currentsong</b> - Shows the title and submitter of the song currently playing.</p>
<p style="-qt-paragraph-type:empty"><br/></p>
@ -191,3 +192,6 @@ const CURRENT_SONG_HTML = `
const CURRENT_SONG_PLAYLIST_HTML = `
The %s currently playing is "%s", added <b>%s</b> from the %s "%s".
`
const SONG_LIST_HTML = `
<br>"%s", added by <b>%s</b<.</br>
`