github.com/wtfutil/wtf@v0.43.0/modules/twitch/settings.go (about) 1 package twitch 2 3 import ( 4 "os" 5 6 "github.com/olebedev/config" 7 "github.com/wtfutil/wtf/cfg" 8 "github.com/wtfutil/wtf/utils" 9 ) 10 11 const ( 12 defaultFocusable = true 13 ) 14 15 type Settings struct { 16 *cfg.Common 17 18 numberOfResults int `help:"Number of results to show. Default is 10." optional:"true"` 19 clientId string `help:"Client Id (default is env var TWITCH_CLIENT_ID)"` 20 clientSecret string `help:"Client secret (default is env var TWITCH_CLIENT_SECRET)"` 21 appAccessToken string `help:"App access token (default is env var TWITCH_APP_ACCESS_TOKEN)"` 22 userAccessToken string `help:"User access token (default is env var TWITCH_USER_ACCESS_TOKEN)"` 23 userRefreshToken string `help:"User refresh token (default is env var TWITCH_USER_REFRESH_TOKEN)"` 24 streams string `help:"Which streams to display. Options: 'top' and 'followed'. Followed requires user access token, user refresh token and user id. Defaults to top."` 25 userId string `help:"Your twitch user ID"` 26 redirectURI string `help:"The redirect URI of your twitch app, mandatory if you wish to see followed streams (default is env var TWITCH_REDIRECT_URI)"` 27 languages []string `help:"Stream languages" optional:"true"` 28 gameIds []string `help:"Twitch Game IDs" optional:"true"` 29 streamType string `help:"Type of stream 'live' (default), 'all', 'vodcast'" optional:"true"` 30 userIds []string `help:"Twitch user ids" optional:"true"` 31 userLogins []string `help:"Twitch user names" optional:"true"` 32 } 33 34 func defaultLanguage() []interface{} { 35 var defaults []interface{} 36 defaults = append(defaults, "en") 37 return defaults 38 } 39 40 func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { 41 twitch := ymlConfig.UString("twitch") 42 settings := Settings{ 43 Common: cfg.NewCommonSettingsFromModule(name, twitch, defaultFocusable, ymlConfig, globalConfig), 44 45 numberOfResults: ymlConfig.UInt("numberOfResults", 10), 46 clientId: ymlConfig.UString("clientId", os.Getenv("TWITCH_CLIENT_ID")), 47 clientSecret: ymlConfig.UString("clientSecret", os.Getenv("TWITCH_CLIENT_SECRET")), 48 appAccessToken: ymlConfig.UString("appAccessToken", os.Getenv("TWITCH_APP_ACCESS_TOKEN")), 49 userAccessToken: ymlConfig.UString("userAccessToken", os.Getenv("TWITCH_USER_ACCESS_TOKEN")), 50 userRefreshToken: ymlConfig.UString("userRefreshToken", os.Getenv("TWITCH_USER_REFRESH_TOKEN")), 51 streams: ymlConfig.UString("streams", "top"), 52 userId: ymlConfig.UString("userId", ""), 53 redirectURI: ymlConfig.UString("redirectURI", os.Getenv("TWITCH_REDIRECT_URI")), 54 languages: utils.ToStrs(ymlConfig.UList("languages", defaultLanguage())), 55 streamType: ymlConfig.UString("streamType", "live"), 56 gameIds: utils.ToStrs(ymlConfig.UList("gameIds", make([]interface{}, 0))), 57 userIds: utils.ToStrs(ymlConfig.UList("userIds", make([]interface{}, 0))), 58 userLogins: utils.ToStrs(ymlConfig.UList("userLogins", make([]interface{}, 0))), 59 } 60 return &settings 61 }