Finished add command

This commit is contained in:
Matthieu Grieger 2014-12-19 21:52:58 -08:00
parent 34eccd1630
commit 5161770cb1
2 changed files with 14 additions and 10 deletions

View file

@ -33,11 +33,9 @@ func parseCommand(user *gumble.User, username, command string) {
if argument == "" { if argument == "" {
user.Send(NO_ARGUMENT_MSG) user.Send(NO_ARGUMENT_MSG)
} else { } else {
success := add(username, argument) success, songTitle := add(username, argument)
if success { if success {
fmt.Println("Add successful!") dj.client.Self().Channel().Send(fmt.Sprintf(SONG_ADDED_HTML, username, songTitle), false)
// TODO: Replace this message with a more informative one.
dj.client.Self().Channel().Send(fmt.Sprintf("%s has added a song to the queue.", username), false)
} else { } else {
user.Send(INVALID_URL_MSG) user.Send(INVALID_URL_MSG)
} }
@ -117,7 +115,7 @@ func parseCommand(user *gumble.User, username, command string) {
} }
} }
func add(user, url string) bool { func add(user, url string) (bool, string) {
youtubePatterns := []string{ youtubePatterns := []string{
`https?:\/\/www\.youtube\.com\/watch\?v=([\w-]+)`, `https?:\/\/www\.youtube\.com\/watch\?v=([\w-]+)`,
`https?:\/\/youtube\.com\/watch\?v=([\w-]+)`, `https?:\/\/youtube\.com\/watch\?v=([\w-]+)`,
@ -140,13 +138,14 @@ func add(user, url string) bool {
if matchFound { if matchFound {
urlMatch := strings.Split(url, "=") urlMatch := strings.Split(url, "=")
shortUrl := urlMatch[1] shortUrl := urlMatch[1]
if dj.queue.AddSong(NewSong(user, shortUrl)) { newSong := NewSong(user, shortUrl)
return true if dj.queue.AddSong(newSong) {
return true, newSong.title
} else { } else {
return false return false, ""
} }
} else { } else {
return false return false, ""
} }
} }

View file

@ -52,7 +52,7 @@ const NOW_PLAYING_HTML = `
// Message shown to channel when a song is added to the queue by a user. // Message shown to channel when a song is added to the queue by a user.
const SONG_ADDED_HTML = ` const SONG_ADDED_HTML = `
<b>%s</b> has voted to skip this song. <b>%s</b> has added "%s" to the queue.
` `
// Message shown to channel when a song has been skipped. // Message shown to channel when a song has been skipped.
@ -64,3 +64,8 @@ const SONG_SKIPPED_HTML = `
const CUR_VOLUME_HTML = ` const CUR_VOLUME_HTML = `
The current volume is <b>%g</b>. The current volume is <b>%g</b>.
` `
// Message shown to users when another user votes to skip the current song.
const SKIP_ADDED_HTML = `
<b>%s</b> has voted to skip the current song.
`