Added an argument for listsongs command that limits the number of songs in the list
This commit is contained in:
parent
f36c18bee7
commit
6210f620bb
|
@ -61,7 +61,7 @@ Command | Description | Arguments | Admin | Example
|
||||||
**numsongs** | Outputs the number of songs in the queue in chat. Individual songs and songs within playlists are both counted. | None | No | `!numsongs`
|
**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`
|
**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`
|
**currentsong** | Outputs the title and name of the submitter of the song currently playing. | None | No | `!currentsong`
|
||||||
**listsongs** | Outputs a list of the songs currently in the queue. | None | No | `!listsongs`
|
**listsongs** | Outputs a list of the songs currently in the queue. | None or desired number of songs to list | No | `!listsongs`
|
||||||
**setcomment** | Sets the comment for the bot. If no argument is given, the current comment will be removed. | None OR new_comment | Yes | `!setcomment Hello! I am a bot. Type !help for the available commands.`
|
**setcomment** | Sets the comment for the bot. If no argument is given, the current comment will be removed. | None OR new_comment | Yes | `!setcomment Hello! I am a bot. Type !help for the available commands.`
|
||||||
**numcached** | Outputs the number of songs currently cached on disk. | None | Yes | `!numcached`
|
**numcached** | Outputs the number of songs currently cached on disk. | None | Yes | `!numcached`
|
||||||
**cachesize** | Outputs the total file size of the cache in MB. | None | Yes | `!cachesize`
|
**cachesize** | Outputs the total file size of the cache in MB. | None | Yes | `!cachesize`
|
||||||
|
|
18
commands.go
18
commands.go
|
@ -188,7 +188,7 @@ func parseCommand(user *gumble.User, username, command string) {
|
||||||
// ListSongs command
|
// ListSongs command
|
||||||
case dj.conf.Aliases.ListSongsAlias:
|
case dj.conf.Aliases.ListSongsAlias:
|
||||||
if dj.HasPermission(username, dj.conf.Permissions.AdminListSongs) {
|
if dj.HasPermission(username, dj.conf.Permissions.AdminListSongs) {
|
||||||
listSongs(user)
|
listSongs(user, argument)
|
||||||
} else {
|
} else {
|
||||||
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
||||||
}
|
}
|
||||||
|
@ -478,11 +478,23 @@ func toggleAutomaticShuffle(activate bool, user *gumble.User, username string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// listSongs handles !listSongs functionality. Sends a private message to the user a list of all songs in the queue
|
// listSongs handles !listSongs functionality. Sends a private message to the user a list of all songs in the queue
|
||||||
func listSongs(user *gumble.User) {
|
func listSongs(user *gumble.User, value string) {
|
||||||
if dj.audioStream.IsPlaying() {
|
if dj.audioStream.IsPlaying() {
|
||||||
|
num := 0
|
||||||
|
if value == "" {
|
||||||
|
num = dj.queue.Len()
|
||||||
|
} else {
|
||||||
|
if parsedNum, err := strconv.Atoi(value); err != nil {
|
||||||
|
num = dj.queue.Len()
|
||||||
|
} else {
|
||||||
|
num = parsedNum
|
||||||
|
}
|
||||||
|
}
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
dj.queue.Traverse(func(i int, song Song) {
|
dj.queue.Traverse(func(i int, song Song) {
|
||||||
buffer.WriteString(fmt.Sprintf(SONG_LIST_HTML, song.Title(), song.Submitter()))
|
if i < num {
|
||||||
|
buffer.WriteString(fmt.Sprintf(SONG_LIST_HTML, i+1, song.Title(), song.Submitter()))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
dj.SendPrivateMessage(user, buffer.String())
|
dj.SendPrivateMessage(user, buffer.String())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -203,6 +203,8 @@ const CURRENT_SONG_HTML = `
|
||||||
const CURRENT_SONG_PLAYLIST_HTML = `
|
const CURRENT_SONG_PLAYLIST_HTML = `
|
||||||
The %s currently playing is "%s", added <b>%s</b> from the %s "%s".
|
The %s currently playing is "%s", added <b>%s</b> from the %s "%s".
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// Message shown to user when the listsongs command is issued
|
||||||
const SONG_LIST_HTML = `
|
const SONG_LIST_HTML = `
|
||||||
<br>"%s", added by <b>%s</b<.</br>
|
<br>%d: "%s", added by <b>%s</b<.</br>
|
||||||
`
|
`
|
||||||
|
|
Reference in a new issue