-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configBot.go
80 lines (70 loc) · 2.27 KB
/
configBot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"io/ioutil"
"golang.org/x/oauth2"
"gopkg.in/yaml.v2"
)
type ConfigBot struct {
UseAWS bool `yaml:"use.aws"`
UseSound bool `yaml:"polly.active"`
UseTrello bool `yaml:"trello.active"`
UseTwitter bool `yaml:"twitter.active"`
OpenAiApiKey string `yaml:"openai.key"`
TrelloKey string `yaml:"trello.key"`
TrelloSecret string `yaml:"trello.secret"`
TrelloAzubiBoard string `yaml:"trello.azubi-board"`
TrelloDokuBoard string `yaml:"trello.doku-board"`
TrelloRedakBoard string `yaml:"trello.redaktions-board"`
AWSRegion string `yaml:"aws.region"`
AWSKey string `yaml:"aws.key"`
AWSSecret string `yaml:"aws.secret"`
PollySampleFile string `yaml:"polly.sample"`
SaveAudioFiles bool `yaml:"polly.safeAudio"`
OauthWordpressToken *oauth2.Token
OauthGoogleToken *oauth2.Token
OauthTwitterToken *oauth2.Token
MaxTokens int `yaml:"bot.MaxTokens"`
Temperature float32 `yaml:"bot.Temperature"`
PresencePenalty float32 `yaml:"bot.PresencePenalty"`
FrequencyPenalty float32 `yaml:"bot.FrequencyPenalty"`
N int `yaml:"bot.N"`
Stop []string `yaml:"bot.Stop"`
ActiveWordpress bool `yaml:"use.wordpress"`
ActiveGoogle bool `yaml:"use.google"`
ActiveTwitter bool `yaml:"use.twitter"`
TwitterToken string `yaml:"twitter.bearer"`
TwitterKey string `yaml:"twitter.key"`
TwitterSecret string `yaml:"twitter.secret"`
}
func GetConfigFromYAMLFile(file string) (*ConfigBot, error) {
var c *ConfigBot
data, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(data, &c)
if err != nil {
return nil, err
}
return c, nil
}
func (c *ConfigBot) SetToken(authToken *oauth2.Token, loginUrl string) {
switch loginUrl {
case "/google":
c.OauthGoogleToken = authToken
case "/wordpress":
c.OauthWordpressToken = authToken
default:
LogError("no used OauthToken", nil)
}
}
func (c *ConfigBot) CheckApiKey() {
if c.OpenAiApiKey == "" {
panic("Missing API KEY")
}
}
func (c *ConfigBot) CheckAWSCredentials() {
if c.AWSKey == "" && c.AWSSecret == "" {
panic("Missing AWS Credentials")
}
}