Added listsongs command

This commit is contained in:
Khoi Tran 2015-12-13 22:34:33 -05:00
parent c5d6b68d5e
commit 6e0b95b9b2
5 changed files with 72 additions and 39 deletions

View file

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

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")
@ -230,9 +229,9 @@ func main() {
}
dj.defaultChannel = strings.Split(channel, "/")
CheckAPIKeys()
dj.client.Attach(gumbleutil.Listener{
Connect: dj.OnConnect,
Disconnect: dj.OnDisconnect,

View file

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

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