Fixed Add command

This commit is contained in:
Matthieu Grieger 2014-12-18 16:28:38 -08:00
parent 7c1933e93f
commit f82e9d9b47

View file

@ -9,15 +9,18 @@ package main
import (
"fmt"
"github.com/kennygrant/sanitize"
"github.com/layeh/gumble/gumble"
"regexp"
"strconv"
"strings"
)
func parseCommand(user *gumble.User, username, command string) {
var com, argument string
if strings.Contains(command, " ") {
parsedCommand := strings.Split(command, " ")
sanitizedCommand := sanitize.HTML(command)
parsedCommand := strings.Split(sanitizedCommand, " ")
com, argument = parsedCommand[0], parsedCommand[1]
} else {
com = command
@ -33,7 +36,10 @@ func parseCommand(user *gumble.User, username, command string) {
success := add(username, argument)
if success {
fmt.Println("Add successful!")
dj.client.Me().Channel().Send(fmt.Sprintf("%s has added a song to the queue.", username))
// 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 {
user.Send(INVALID_URL_MSG)
}
}
} else {
@ -44,6 +50,7 @@ func parseCommand(user *gumble.User, username, command string) {
success := skip(username, false)
if success {
fmt.Println("Skip successful!")
dj.client.Self().Channel().Send(fmt.Sprintf(SKIP_ADDED_HTML, username), false)
}
} else {
user.Send(NO_PERMISSION_MSG)
@ -64,7 +71,7 @@ func parseCommand(user *gumble.User, username, command string) {
} else {
success := volume(username, argument)
if success {
fmt.Println("Skip successful!")
fmt.Println("Volume change successful!")
}
}
} else {
@ -78,6 +85,8 @@ func parseCommand(user *gumble.User, username, command string) {
success := move(username, argument)
if success {
fmt.Printf("%s has been moved to %s.", dj.client.Self().Name(), argument)
} else {
user.Send(CHANNEL_DOES_NOT_EXIST_MSG)
}
}
} else {
@ -129,7 +138,9 @@ func add(user, url string) bool {
}
if matchFound {
if dj.queue.AddSong(NewSong(user, url)) {
urlMatch := strings.Split(url, "=")
shortUrl := urlMatch[1]
if dj.queue.AddSong(NewSong(user, shortUrl)) {
return true
} else {
return false
@ -144,7 +155,18 @@ func skip(user string, admin bool) bool {
}
func volume(user, value string) bool {
return true
parsedVolume, err := strconv.ParseFloat(value, 32)
if err == nil {
newVolume := float32(parsedVolume)
if newVolume >= dj.conf.Volume.LowestVolume && newVolume <= dj.conf.Volume.HighestVolume {
dj.conf.Volume.DefaultVolume = newVolume
return true
} else {
return false
}
} else {
return false
}
}
func move(user, channel string) bool {