-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
74 lines (64 loc) · 1.59 KB
/
config.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
package main
import (
"encoding/json"
"os"
log "github.com/sirupsen/logrus"
)
type Config struct {
Name string `json:"name"`
Organisations []Organisation `json:"organisations"`
OrganisationsFile string `json:"organisations_file"`
MinDiff int `json:"min_diff"`
Mastodon MastodonAccount `json:"mastodon"`
Twitter TwitterAccount `json:"twitter"`
}
type MastodonAccount struct {
Server string `json:"server"`
ClientKey string `json:"client_key"`
ClientSecret string `json:"client_secret"`
AccessToken string `json:"access_token"`
}
type TwitterAccount struct {
ConsumerKey string `json:"consumer_key"`
ConsumerSecret string `json:"consumer_secret"`
AccessToken string `json:"access_token"`
AccessSecret string `json:"access_secret"`
}
func (c Config) hasMastodon() bool {
if c.Mastodon.Server != "" &&
c.Mastodon.ClientKey != "" &&
c.Mastodon.ClientSecret != "" &&
c.Mastodon.AccessToken != "" {
return true
} else {
return false
}
}
func (c Config) hasTwitter() bool {
if c.Twitter.ConsumerKey != "" &&
c.Twitter.ConsumerSecret != "" &&
c.Twitter.AccessToken != "" &&
c.Twitter.AccessSecret != "" {
return true
} else {
return false
}
}
func (c Config) loadFile(path string) *Config {
log.WithField("filename", path).Debug("Loading config file")
data, err := os.ReadFile(path)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(data, &c)
if err != nil {
log.Fatal(err)
}
return &c
}
func NewConfig() Config {
return Config{
Name: "Default bot",
MinDiff: 10,
}
}