Added nextsong command

pull/29/merge 2.2.8
Matthieu Grieger 2015-01-12 16:21:53 -08:00
parent 98d2ce08ab
commit 4376fe7394
7 changed files with 44 additions and 2 deletions

View File

@ -1,6 +1,9 @@
MumbleDJ Changelog
==================
### January 12, 2015 -- `v2.2.8`
* Added !nextsong command, which outputs some information about the next song in the queue if it exists.
### January 10, 2015 -- `v2.2.6, v2.2.7`
* Fixed type mismatch error when building MumbleDJ.
* Added traversal function to SongQueue.

View File

@ -24,6 +24,7 @@ Command | Description | Arguments | Admin | Example
**reload** | Reloads `mumbledj.gcfg` to retrieve updated configuration settings. | None | Yes | `!reload`
**reset** | Stops all audio and resets the song queue. | None | Yes | `!reset`
**numsongs** | Outputs the number of songs in the queue in chat. Individual songs and songs within playlists are both counted. | None | No | `!numsongs`
**nextsong** | Outputs the title and name of the submitter of the next song in the queue if it exists. | None | No | `!nextsong`
**kill** | Safely cleans the bot environment and disconnects from the server. Please use this command to stop the bot instead of force closing, as the kill command deletes any remaining songs in the `~/.mumbledj/songs` directory. | None | Yes | `!kill`

View File

@ -109,6 +109,13 @@ func parseCommand(user *gumble.User, username, command string) {
} else {
user.Send(NO_PERMISSION_MSG)
}
// Nextsong command
case dj.conf.Aliases.NextSongAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminNextSong) {
nextSong(user)
} else {
user.Send(NO_PERMISSION_MSG)
}
// Kill command
case dj.conf.Aliases.KillAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminKill) {
@ -314,6 +321,17 @@ func numSongs() {
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
// item if it exists. The user will then be sent a message containing the title and submitter
// of the next item if it exists.
func nextSong(user *gumble.User) {
if title, submitter, err := dj.queue.PeekNext(); err != nil {
user.Send(NO_SONG_NEXT_MSG)
} else {
user.Send(fmt.Sprintf(NEXT_SONG_HTML, title, submitter))
}
}
// 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.
func kill() {

View File

@ -75,6 +75,10 @@ ResetAlias = "reset"
# DEFAULT VALUE: "numsongs"
NumSongsAlias = "numsongs"
# Alias used for nextsong command
# DEFAULT VALUE: "nextsong"
NextSongAlias = "nextsong"
# Alias used for kill command
# DEFAULT VALUE: "kill"
KillAlias = "kill"
@ -131,6 +135,10 @@ AdminReset = true
# DEFAULT VALUE: false
AdminNumSongs = false
# Make nextsong an admin command?
# DEFAULT VALUE: false
AdminNextSong = false
# Make kill an admin command?
# DEFAULT VALUE: true (I recommend never changing this to false)
AdminKill = true

View File

@ -37,6 +37,7 @@ type DjConfig struct {
ReloadAlias string
ResetAlias string
NumSongsAlias string
NextSongAlias string
KillAlias string
}
Permissions struct {
@ -51,6 +52,7 @@ type DjConfig struct {
AdminReload bool
AdminReset bool
AdminNumSongs bool
AdminNextSong bool
AdminKill bool
}
}

View File

@ -57,7 +57,7 @@ func (q *SongQueue) NextItem() {
func (q *SongQueue) PeekNext() (string, string, error) {
var title, submitter string
if q.Len() > 1 {
if q.queue[1].ItemType == "playlist" {
if q.queue[1].ItemType() == "playlist" {
title = q.queue[1].(*Playlist).songs.queue[0].(*Song).title
submitter = q.queue[1].(*Playlist).submitter
} else {
@ -65,7 +65,9 @@ func (q *SongQueue) PeekNext() (string, string, error) {
submitter = q.queue[1].(*Song).submitter
}
return title, submitter, nil
} else if q.CurrentItem().ItemType == "playlist" {
} else if q.Len() == 0 {
return "", "", errors.New("There is no item next in the queue.")
} else if q.CurrentItem().ItemType() == "playlist" {
title = q.CurrentItem().(*Playlist).songs.queue[1].(*Song).title
submitter = q.CurrentItem().(*Playlist).submitter
return title, submitter, nil

View File

@ -29,6 +29,9 @@ const NO_MUSIC_PLAYING_MSG = "There is no music playing at the moment."
// Message shown to users when they attempt to skip a playlist when there is no playlist playing.
const NO_PLAYLIST_PLAYING_MSG = "There is no playlist playing at the moment."
// Message shown to users when they attempt to use the nextsong command when there is no song coming up.
const NO_SONG_NEXT_MSG = "There are no songs queued at the moment."
// Message shown to users when they issue a command that requires an argument and one was not supplied.
const NO_ARGUMENT_MSG = "The command you issued requires an argument and you did not provide one."
@ -129,3 +132,8 @@ const QUEUE_RESET_HTML = `
const NUM_SONGS_HTML = `
There are currently <b>%d</b> song(s) in the queue.
`
// Message shown to users when they issue the nextsong command.
const NEXT_SONG_HTML = `
The next song in the queue is "%s", added by <b>%s</b>.
`