1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/twitch/settings.go
2019-12-30 22:20:53 -05:00

46 lines
1.7 KiB
Go

package twitch
import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/utils"
"os"
)
const (
defaultFocusable = true
)
type Settings struct {
common *cfg.Common
numberOfResults int `help:"Number of results to show. Default is 10." optional:"true"`
clientId string `help:"Client Id (default is env var TWITCH_CLIENT_ID)"`
languages []string `help:"Stream languages" optional:"true"`
gameIds []string `help:"Twitch Game IDs" optional:"true"`
streamType string `help:"Type of stream 'live' (default), 'all', 'vodcast'" optional:"true"`
userIds []string `help:"Twitch user ids" optional:"true"`
userLogins []string `help:"Twitch user names" optional:"true"`
}
func defaultLanguage() []interface{} {
var defaults []interface{}
defaults = append(defaults, "en")
return defaults
}
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
twitch := ymlConfig.UString("twitch")
settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, twitch, defaultFocusable, ymlConfig, globalConfig),
numberOfResults: ymlConfig.UInt("numberOfResults", 10),
clientId: ymlConfig.UString("clientId", os.Getenv("TWITCH_CLIENT_ID")),
languages: utils.ToStrs(ymlConfig.UList("languages", defaultLanguage())),
streamType: ymlConfig.UString("streamType", "live"),
gameIds: utils.ToStrs(ymlConfig.UList("gameIds", make([]interface{}, 0))),
userIds: utils.ToStrs(ymlConfig.UList("userIds", make([]interface{}, 0))),
userLogins: utils.ToStrs(ymlConfig.UList("userLogins", make([]interface{}, 0))),
}
return &settings
}