Fixed Add command
This commit is contained in:
parent
7c1933e93f
commit
f82e9d9b47
32
commands.go
32
commands.go
|
@ -9,15 +9,18 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/kennygrant/sanitize"
|
||||||
"github.com/layeh/gumble/gumble"
|
"github.com/layeh/gumble/gumble"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseCommand(user *gumble.User, username, command string) {
|
func parseCommand(user *gumble.User, username, command string) {
|
||||||
var com, argument string
|
var com, argument string
|
||||||
if strings.Contains(command, " ") {
|
if strings.Contains(command, " ") {
|
||||||
parsedCommand := strings.Split(command, " ")
|
sanitizedCommand := sanitize.HTML(command)
|
||||||
|
parsedCommand := strings.Split(sanitizedCommand, " ")
|
||||||
com, argument = parsedCommand[0], parsedCommand[1]
|
com, argument = parsedCommand[0], parsedCommand[1]
|
||||||
} else {
|
} else {
|
||||||
com = command
|
com = command
|
||||||
|
@ -33,7 +36,10 @@ func parseCommand(user *gumble.User, username, command string) {
|
||||||
success := add(username, argument)
|
success := add(username, argument)
|
||||||
if success {
|
if success {
|
||||||
fmt.Println("Add successful!")
|
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 {
|
} else {
|
||||||
|
@ -44,6 +50,7 @@ func parseCommand(user *gumble.User, username, command string) {
|
||||||
success := skip(username, false)
|
success := skip(username, false)
|
||||||
if success {
|
if success {
|
||||||
fmt.Println("Skip successful!")
|
fmt.Println("Skip successful!")
|
||||||
|
dj.client.Self().Channel().Send(fmt.Sprintf(SKIP_ADDED_HTML, username), false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
user.Send(NO_PERMISSION_MSG)
|
user.Send(NO_PERMISSION_MSG)
|
||||||
|
@ -64,7 +71,7 @@ func parseCommand(user *gumble.User, username, command string) {
|
||||||
} else {
|
} else {
|
||||||
success := volume(username, argument)
|
success := volume(username, argument)
|
||||||
if success {
|
if success {
|
||||||
fmt.Println("Skip successful!")
|
fmt.Println("Volume change successful!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,6 +85,8 @@ func parseCommand(user *gumble.User, username, command string) {
|
||||||
success := move(username, argument)
|
success := move(username, argument)
|
||||||
if success {
|
if success {
|
||||||
fmt.Printf("%s has been moved to %s.", dj.client.Self().Name(), argument)
|
fmt.Printf("%s has been moved to %s.", dj.client.Self().Name(), argument)
|
||||||
|
} else {
|
||||||
|
user.Send(CHANNEL_DOES_NOT_EXIST_MSG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -129,7 +138,9 @@ func add(user, url string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if matchFound {
|
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
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
@ -144,7 +155,18 @@ func skip(user string, admin bool) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func volume(user, value string) 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 {
|
func move(user, channel string) bool {
|
||||||
|
|
Reference in a new issue