mastodon-group-bot/config.go

43 lines
940 B
Go
Raw Normal View History

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