Add currentsong command
This commit is contained in:
parent
5cd7f7c6c2
commit
9940939542
|
@ -1,6 +1,9 @@
|
|||
MumbleDJ Changelog
|
||||
==================
|
||||
|
||||
### January 25, 2015 -- `v2.3.0`
|
||||
* Added !currentsong command, which displays information about the song currently playing.
|
||||
|
||||
### January 19, 2015 -- `v2.2.11`
|
||||
* Fixed not being able to use the move command with channels with spaces in their name.
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ Command | Description | Arguments | Admin | Example
|
|||
**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`
|
||||
**currentsong** | Outputs the title and name of the submitter of the song currently playing. | None | No | `!currentsong`
|
||||
**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`
|
||||
|
||||
|
||||
|
|
25
commands.go
25
commands.go
|
@ -25,7 +25,7 @@ func parseCommand(user *gumble.User, username, command string) {
|
|||
sanitizedCommand := sanitize.HTML(command)
|
||||
if strings.Contains(sanitizedCommand, " ") {
|
||||
index := strings.Index(sanitizedCommand, " ")
|
||||
com, argument = sanitizedCommand[0:index], sanitizedCommand[(index + 1):]
|
||||
com, argument = sanitizedCommand[0:index], sanitizedCommand[(index+1):]
|
||||
} else {
|
||||
com = command
|
||||
argument = ""
|
||||
|
@ -116,6 +116,13 @@ func parseCommand(user *gumble.User, username, command string) {
|
|||
} else {
|
||||
user.Send(NO_PERMISSION_MSG)
|
||||
}
|
||||
// Currentsong command
|
||||
case dj.conf.Aliases.CurrentSongAlias:
|
||||
if dj.HasPermission(username, dj.conf.Permissions.AdminCurrentSong) {
|
||||
currentSong(user)
|
||||
} else {
|
||||
user.Send(NO_PERMISSION_MSG)
|
||||
}
|
||||
// Kill command
|
||||
case dj.conf.Aliases.KillAlias:
|
||||
if dj.HasPermission(username, dj.conf.Permissions.AdminKill) {
|
||||
|
@ -332,6 +339,22 @@ func nextSong(user *gumble.User) {
|
|||
}
|
||||
}
|
||||
|
||||
// Performs currentsong functionality. Sends the user who submitted the currentsong command
|
||||
// information about the song currently playing.
|
||||
func currentSong(user *gumble.User) {
|
||||
if dj.audioStream.IsPlaying() {
|
||||
var currentItem *Song
|
||||
if dj.queue.CurrentItem().ItemType() == "playlist" {
|
||||
currentItem = dj.queue.CurrentItem().(*Playlist).songs.CurrentItem().(*Song)
|
||||
} else {
|
||||
currentItem = dj.queue.CurrentItem().(*Song)
|
||||
}
|
||||
user.Send(fmt.Sprintf(CURRENT_SONG_HTML, currentItem.title, currentItem.submitter))
|
||||
} else {
|
||||
user.Send(NO_MUSIC_PLAYING_MSG)
|
||||
}
|
||||
}
|
||||
|
||||
// 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() {
|
||||
|
|
|
@ -79,6 +79,10 @@ NumSongsAlias = "numsongs"
|
|||
# DEFAULT VALUE: "nextsong"
|
||||
NextSongAlias = "nextsong"
|
||||
|
||||
# Alias used for the currentsong command
|
||||
# DEFAULT VALUE: "currentsong"
|
||||
CurrentSongAlias = "currentsong"
|
||||
|
||||
# Alias used for kill command
|
||||
# DEFAULT VALUE: "kill"
|
||||
KillAlias = "kill"
|
||||
|
@ -139,6 +143,10 @@ AdminNumSongs = false
|
|||
# DEFAULT VALUE: false
|
||||
AdminNextSong = false
|
||||
|
||||
# Make currentsong an admin command?
|
||||
# DEFAULT VALUE: false
|
||||
AdminCurrentSong = false
|
||||
|
||||
# Make kill an admin command?
|
||||
# DEFAULT VALUE: true (I recommend never changing this to false)
|
||||
AdminKill = true
|
||||
|
|
|
@ -38,6 +38,7 @@ type DjConfig struct {
|
|||
ResetAlias string
|
||||
NumSongsAlias string
|
||||
NextSongAlias string
|
||||
CurrentSongAlias string
|
||||
KillAlias string
|
||||
}
|
||||
Permissions struct {
|
||||
|
@ -53,6 +54,7 @@ type DjConfig struct {
|
|||
AdminReset bool
|
||||
AdminNumSongs bool
|
||||
AdminNextSong bool
|
||||
AdminCurrentSong bool
|
||||
AdminKill bool
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ const HELP_HTML = `<br/>
|
|||
<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>!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>
|
||||
<p><b>Admin Commands:</b></p>
|
||||
<p><b>!reset</b> - An admin command that resets the song queue. </p>
|
||||
|
@ -139,3 +140,8 @@ const NUM_SONGS_HTML = `
|
|||
const NEXT_SONG_HTML = `
|
||||
The next song in the queue is "%s", added by <b>%s</b>.
|
||||
`
|
||||
|
||||
// Message shown to users when they issue the currentsong command.
|
||||
const CURRENT_SONG_HTML = `
|
||||
The song currently playing is "%s", added by <b>%s</b>.
|
||||
`
|
||||
|
|
Reference in a new issue