mastodon-group-bot/config.go

46 lines
1.1 KiB
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 {
2022-09-08 15:26:25 +03:00
Server string `json:"Server"`
ClientID string `json:"ClientID"`
ClientSecret string `json:"ClientSecret"`
AccessToken string `json:"AccessToken"`
WelcomeMessage string `json:"WelcomeMessage"`
NotFollowedMessage string `json:"NotFollowedMessage"`
Max_toots uint `json:"Max_toots"`
Toots_interval uint `json:"Toots_interval"`
Duplicate_buf uint `json:"Duplicate_buf"`
Order_limit uint `json:"Order_limit"`
Del_notices_interval uint `json:"Del_notices_interval"`
Admins []string `json:"Admins"`
2022-08-22 14:46:49 +03:00
}
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
}