Now uses config, response messages added

This commit is contained in:
Matthieu Grieger 2014-12-15 16:40:05 -08:00
parent 6721a7f51f
commit 7f6d764821

View file

@ -9,10 +9,12 @@ package main
import (
"fmt"
"github.com/layeh/gumble/gumble"
"regexp"
"strings"
)
func parseCommand(username, command string) {
func parseCommand(user *gumble.User, username, command string) {
var com, argument string
if strings.Contains(command, " ") {
parsedCommand := strings.Split(command, " ")
@ -21,48 +23,120 @@ func parseCommand(username, command string) {
com = command
argument = ""
}
switch com {
case dj.conf.Aliases.AddAlias:
success := add(username, argument)
if success {
fmt.Println("Add successful!")
case dj.conf.Aliases.AddAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminAdd) {
if argument == "" {
user.Send(NO_ARGUMENT_MSG)
} else {
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))
}
}
case dj.conf.Aliases.SkipAlias:
} else {
user.Send(NO_PERMISSION_MSG)
}
case dj.conf.Aliases.SkipAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminSkip) {
success := skip(username, false)
if success {
fmt.Println("Skip successful!")
}
case dj.conf.Aliases.AdminSkipAlias:
} else {
user.Send(NO_PERMISSION_MSG)
}
case dj.conf.Aliases.AdminSkipAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminSkip) {
success := skip(username, true)
if success {
fmt.Println("Forceskip successful!")
}
case dj.conf.Aliases.VolumeAlias:
success := volume(username, argument)
if success {
fmt.Println("Volume change successful!")
} else {
user.Send(NO_PERMISSION_MSG)
}
case dj.conf.Aliases.VolumeAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminVolume) {
if argument == "" {
dj.client.Self().Channel().Send(fmt.Sprintf(CUR_VOLUME_HTML, dj.conf.Volume.DefaultVolume), false)
} else {
success := volume(username, argument)
if success {
fmt.Println("Skip successful!")
}
}
case dj.conf.Aliases.MoveAlias:
success := move(username, argument)
if success {
fmt.Println("Move successful!")
} else {
user.Send(NO_PERMISSION_MSG)
}
case dj.conf.Aliases.MoveAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminMove) {
if argument == "" {
user.Send(NO_ARGUMENT_MSG)
} else {
success := move(username, argument)
if success {
fmt.Printf("%s has been moved to %s.", dj.client.Self().Name(), argument)
}
}
case dj.conf.Aliases.ReloadAlias:
} else {
user.Send(NO_PERMISSION_MSG)
}
case dj.conf.Aliases.ReloadAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminReload) {
err := loadConfiguration()
if err == nil {
fmt.Println("Reload successful!")
user.Send(CONFIG_RELOAD_SUCCESS_MSG)
} else {
panic(err)
}
case dj.conf.Aliases.KillAlias:
} else {
user.Send(NO_PERMISSION_MSG)
}
case dj.conf.Aliases.KillAlias:
if dj.HasPermission(username, dj.conf.Permissions.AdminKill) {
success := kill(username)
if success {
fmt.Println("Kill successful!")
}
} else {
user.Send(NO_PERMISSION_MSG)
}
default:
user.Send(COMMAND_DOESNT_EXIST_MSG)
}
}
func add(user, url string) bool {
return true
youtubePatterns := []string{
`https?:\/\/www\.youtube\.com\/watch\?v=([\w-]+)`,
`https?:\/\/youtube\.com\/watch\?v=([\w-]+)`,
`https?:\/\/youtu.be\/([\w-]+)`,
`https?:\/\/youtube.com\/v\/([\w-]+)`,
`https?:\/\/www.youtube.com\/v\/([\w-]+)`,
}
matchFound := false
for _, pattern := range youtubePatterns {
re, err := regexp.Compile(pattern)
if err == nil {
if re.MatchString(url) {
matchFound = true
break
}
}
}
if matchFound {
if dj.queue.AddSong(NewSong(user, url)) {
return true
} else {
return false
}
} else {
return false
}
}
func skip(user string, admin bool) bool {