Add request https://github.com/matthieugrieger/mumbledj/issues/15: numsongs command
This commit is contained in:
parent
aa60f2bad7
commit
a31da73f39
18
commands.go
18
commands.go
|
@ -95,6 +95,13 @@ func parseCommand(user *gumble.User, username, command string) {
|
||||||
} else {
|
} else {
|
||||||
user.Send(NO_PERMISSION_MSG)
|
user.Send(NO_PERMISSION_MSG)
|
||||||
}
|
}
|
||||||
|
// Numsongs command
|
||||||
|
case dj.conf.Aliases.NumSongsAlias:
|
||||||
|
if dj.HasPermission(username, dj.conf.Permissions.AdminNumSongs) {
|
||||||
|
numSongs()
|
||||||
|
} else {
|
||||||
|
user.Send(NO_PERMISSION_MSG)
|
||||||
|
}
|
||||||
// Kill command
|
// Kill command
|
||||||
case dj.conf.Aliases.KillAlias:
|
case dj.conf.Aliases.KillAlias:
|
||||||
if dj.HasPermission(username, dj.conf.Permissions.AdminKill) {
|
if dj.HasPermission(username, dj.conf.Permissions.AdminKill) {
|
||||||
|
@ -284,6 +291,17 @@ func reset(username string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Performs numsongs functionality. Uses the SongQueue traversal function to traverse the
|
||||||
|
// queue with a function call that increments a counter. Once finished, the bot outputs
|
||||||
|
// the number of songs in the queue to chat.
|
||||||
|
func numSongs() {
|
||||||
|
songCount := 0
|
||||||
|
dj.queue.Traverse(func(i int, item QueueItem) {
|
||||||
|
songCount += 1
|
||||||
|
})
|
||||||
|
dj.client.Self().Channel().Send(fmt.Sprintf(NUM_SONGS_HTML, songCount), false)
|
||||||
|
}
|
||||||
|
|
||||||
// Performs kill functionality. First cleans the ~/.mumbledj/songs directory to get rid of any
|
// Performs kill functionality. First cleans the ~/.mumbledj/songs directory to get rid of any
|
||||||
// excess m4a files. The bot then safely disconnects from the server.
|
// excess m4a files. The bot then safely disconnects from the server.
|
||||||
func kill() {
|
func kill() {
|
||||||
|
|
|
@ -67,6 +67,10 @@ ReloadAlias = "reload"
|
||||||
# DEFAULT VALUE: "reset"
|
# DEFAULT VALUE: "reset"
|
||||||
ResetAlias = "reset"
|
ResetAlias = "reset"
|
||||||
|
|
||||||
|
# Alias used for numsongs command
|
||||||
|
# DEFAULT VALUE: "numsongs"
|
||||||
|
NumSongsAlias = "numsongs"
|
||||||
|
|
||||||
# Alias used for kill command
|
# Alias used for kill command
|
||||||
# DEFAULT VALUE: "kill"
|
# DEFAULT VALUE: "kill"
|
||||||
KillAlias = "kill"
|
KillAlias = "kill"
|
||||||
|
@ -115,6 +119,10 @@ AdminReload = true
|
||||||
# DEFAULT VALUE: true
|
# DEFAULT VALUE: true
|
||||||
AdminReset = true
|
AdminReset = true
|
||||||
|
|
||||||
|
# Make numsongs an admin command?
|
||||||
|
# DEFAULT VALUE: false
|
||||||
|
AdminNumSongs = false
|
||||||
|
|
||||||
# Make kill an admin command?
|
# Make kill an admin command?
|
||||||
# DEFAULT VALUE: true (I recommend never changing this to false)
|
# DEFAULT VALUE: true (I recommend never changing this to false)
|
||||||
AdminKill = true
|
AdminKill = true
|
||||||
|
|
|
@ -35,6 +35,7 @@ type DjConfig struct {
|
||||||
MoveAlias string
|
MoveAlias string
|
||||||
ReloadAlias string
|
ReloadAlias string
|
||||||
ResetAlias string
|
ResetAlias string
|
||||||
|
NumSongsAlias string
|
||||||
KillAlias string
|
KillAlias string
|
||||||
}
|
}
|
||||||
Permissions struct {
|
Permissions struct {
|
||||||
|
@ -47,6 +48,7 @@ type DjConfig struct {
|
||||||
AdminMove bool
|
AdminMove bool
|
||||||
AdminReload bool
|
AdminReload bool
|
||||||
AdminReset bool
|
AdminReset bool
|
||||||
|
AdminNumSongs bool
|
||||||
AdminKill bool
|
AdminKill bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15
songqueue.go
15
songqueue.go
|
@ -58,6 +58,21 @@ func (q *SongQueue) Len() int {
|
||||||
return len(q.queue)
|
return len(q.queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A traversal function for SongQueue. Allows a visit function to be passed in which performs
|
||||||
|
// the specified action on each queue item. Traverses all individual songs, and all songs
|
||||||
|
// within playlists.
|
||||||
|
func (q *SongQueue) Traverse(visit func(i int, item QueueItem)) {
|
||||||
|
for iQueue, queueItem := range q.queue {
|
||||||
|
if queueItem.ItemType() == "playlist" {
|
||||||
|
for iPlaylist, playlistItem := range q.queue[iQueue].(*Playlist).songs.queue {
|
||||||
|
visit(iPlaylist, playlistItem)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
visit(iQueue, queueItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// OnItemFinished event. Deletes item that just finished playing, then queues the next item.
|
// OnItemFinished event. Deletes item that just finished playing, then queues the next item.
|
||||||
func (q *SongQueue) OnItemFinished() {
|
func (q *SongQueue) OnItemFinished() {
|
||||||
if q.Len() != 0 {
|
if q.Len() != 0 {
|
||||||
|
|
|
@ -106,3 +106,8 @@ const VOLUME_SUCCESS_HTML = `
|
||||||
const QUEUE_RESET_HTML = `
|
const QUEUE_RESET_HTML = `
|
||||||
<b>%s</b> has cleared the song queue.
|
<b>%s</b> has cleared the song queue.
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// Message shown to users when a user asks how many songs are in the queue.
|
||||||
|
const NUM_SONGS_HTML = `
|
||||||
|
There are currently <b>%d</b> song(s) in the queue.
|
||||||
|
`
|
||||||
|
|
Reference in a new issue