mastodon-group-bot/config.go

43 lines
940 B
Go
Raw Normal View History

2022-08-22 11:46:49 +00:00
package main
import (
"encoding/json"
"flag"
"log"
"os"
)
2022-08-28 16:37:43 +00:00
var (
ConfPath = flag.String("config", "config.json", "Path to config")
2022-09-01 11:31:27 +00:00
DBPath = flag.String("db", "mastodon-group-bot.db", "Path to database")
2022-08-28 16:37:43 +00:00
LogPath = flag.String("log", "mastodon-group-bot.log", "Path to log")
2022-09-01 11:31:27 +00:00
Conf = ReadConfig()
2022-08-28 16:37:43 +00:00
)
2022-08-22 11:46:49 +00:00
type Config struct {
Server string `json:"Server"`
ClientID string `json:"ClientID"`
ClientSecret string `json:"ClientSecret"`
AccessToken string `json:"AccessToken"`
WelcomeMessage string `json:"WelcomeMessage"`
2022-08-25 19:23:44 +00:00
Max_toots uint16 `json:"Max_toots"`
Toots_interval uint16 `json:"Toots_interval"`
2022-09-01 11:31:27 +00:00
Duplicate_buf int `json:"Duplicate_buf"`
2022-08-22 11:46:49 +00:00
Admins []string `json:"Admins"`
}
2022-09-01 11:31:27 +00:00
func ReadConfig() Config {
2022-08-22 11:46:49 +00:00
flag.Parse()
data, err := os.ReadFile(*ConfPath)
if err != nil {
2022-08-28 16:37:43 +00:00
log.Fatal("Failed to read config")
2022-08-22 11:46:49 +00:00
}
var Conf Config
json.Unmarshal(data, &Conf)
2022-08-28 16:37:43 +00:00
return Conf
2022-08-22 11:46:49 +00:00
}