Enables/Disables services based on whether API key exists
This commit is contained in:
parent
fdfe97cd81
commit
14ae00973d
25
main.go
25
main.go
|
@ -133,28 +133,39 @@ func (dj *mumbledj) SendPrivateMessage(user *gumble.User, message string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformStartupChecks checks the MumbleDJ installation to ensure proper usage.
|
// CheckAPIKeys enables the services with API keys in the environment varaibles
|
||||||
func PerformStartupChecks() {
|
func CheckAPIKeys() {
|
||||||
|
// Checks YouTube API key
|
||||||
if os.Getenv("YOUTUBE_API_KEY") == "" {
|
if os.Getenv("YOUTUBE_API_KEY") == "" {
|
||||||
fmt.Printf("You do not have a YouTube API key defined in your environment variables.\n" +
|
fmt.Printf("The youtube service has been disabled as you do not have a YouTube API key defined in your environment variables.\n" +
|
||||||
"Please see the following link for info on how to fix this: https://github.com/matthieugrieger/mumbledj#youtube-api-keys\n")
|
"Please see the following link for info on how to fix this: https://github.com/matthieugrieger/mumbledj#youtube-api-keys\n")
|
||||||
os.Exit(1)
|
} else {
|
||||||
|
AddService(YouTube{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks Soundcloud API key
|
||||||
|
if os.Getenv("SOUNDCLOUD_API_KEY") == "" {
|
||||||
|
fmt.Printf("The soundcloud service has been disabled as you do not have a Soundcloud API key defined in your environment variables.\n" +
|
||||||
|
"Please see the following link for info on how to fix this: https://github.com/matthieugrieger/mumbledj#soundcloud-api-keys\n")
|
||||||
|
} else {
|
||||||
|
AddService(SoundCloud{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints out messages only if verbose flag is true
|
// Verbose prints out messages only if verbose flag is true
|
||||||
func Verbose(msg string) {
|
func Verbose(msg string) {
|
||||||
if dj.verbose {
|
if dj.verbose {
|
||||||
fmt.Printf(msg + "\n")
|
fmt.Printf(msg + "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks to see if an object is nil
|
// isNil checks to see if an object is nil
|
||||||
func isNil(a interface{}) bool {
|
func isNil(a interface{}) bool {
|
||||||
defer func() { recover() }()
|
defer func() { recover() }()
|
||||||
return a == nil || reflect.ValueOf(a).IsNil()
|
return a == nil || reflect.ValueOf(a).IsNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegexpFromURL loops through an array of patterns to see if it matches the url
|
||||||
func RegexpFromURL(url string, patterns []string) *regexp.Regexp {
|
func RegexpFromURL(url string, patterns []string) *regexp.Regexp {
|
||||||
for _, pattern := range patterns {
|
for _, pattern := range patterns {
|
||||||
if re, err := regexp.Compile(pattern); err == nil {
|
if re, err := regexp.Compile(pattern); err == nil {
|
||||||
|
@ -178,7 +189,7 @@ var dj = mumbledj{
|
||||||
// args, sets up the gumble client and its listeners, and then connects to the server.
|
// args, sets up the gumble client and its listeners, and then connects to the server.
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
PerformStartupChecks()
|
CheckAPIKeys()
|
||||||
|
|
||||||
if currentUser, err := user.Current(); err == nil {
|
if currentUser, err := user.Current(); err == nil {
|
||||||
dj.homeDir = currentUser.HomeDir
|
dj.homeDir = currentUser.HomeDir
|
||||||
|
|
10
service.go
10
service.go
|
@ -52,7 +52,15 @@ type Playlist interface {
|
||||||
Title() string
|
Title() string
|
||||||
}
|
}
|
||||||
|
|
||||||
var services = []Service{YouTube{}, SoundCloud{}}
|
var services []Service
|
||||||
|
|
||||||
|
func AddService(service Service) {
|
||||||
|
if services == nil {
|
||||||
|
service = Service{service}
|
||||||
|
} else {
|
||||||
|
service = append(service, services)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func findServiceAndAdd(user *gumble.User, url string) error {
|
func findServiceAndAdd(user *gumble.User, url string) error {
|
||||||
var urlService Service
|
var urlService Service
|
||||||
|
|
Reference in a new issue