2020-05-09 01:51:02 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
"golang.org/x/oauth2/twitch"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
settings *Settings
|
|
|
|
twitchOauthConfig *oauth2.Config
|
|
|
|
)
|
|
|
|
|
|
|
|
type Settings struct {
|
|
|
|
ClientID string `yaml:"client_id"`
|
|
|
|
ClientSecret string `yaml:"client_secret"`
|
2020-05-09 22:46:45 +02:00
|
|
|
RedirectURL string `yaml:"redirect_url"`
|
2020-05-09 01:51:02 +02:00
|
|
|
VerificationToken string `yaml:"verification_token"`
|
2020-05-09 03:38:08 +02:00
|
|
|
WebserverPort string `yaml:"webserver_port"`
|
2020-05-09 01:51:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func loadSettings() {
|
|
|
|
data, err := ioutil.ReadFile(cfg.SettingsFile)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Errorf("Unable to read %s", cfg.SettingsFile)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s := &Settings{}
|
|
|
|
b := bytes.NewBuffer(data)
|
|
|
|
if err := yaml.NewDecoder(b).Decode(s); err != nil {
|
|
|
|
log.WithError(err).Errorf("Unable to decode %s", cfg.SettingsFile)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
settings = s
|
|
|
|
|
|
|
|
twitchOauthConfig = &oauth2.Config{
|
2020-05-09 22:39:27 +02:00
|
|
|
RedirectURL: settings.RedirectURL,
|
2020-05-09 01:51:02 +02:00
|
|
|
ClientID: settings.ClientID,
|
|
|
|
ClientSecret: settings.ClientSecret,
|
|
|
|
Scopes: []string{"channel:read:subscriptions", "user:read:broadcast", "chat:read", "chat:edit", "channel_read", "channel_editor", "channel_subscriptions", "channel:moderate", "bits:read", "channel:read:redemptions"},
|
|
|
|
Endpoint: twitch.Endpoint,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func settingsUpdater() {
|
|
|
|
loadSettings()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
c := time.Tick(time.Minute)
|
|
|
|
for range c {
|
|
|
|
loadSettings()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|