mastodon-group-bot/config.go

46 lines
1.1 KiB
Go
Raw Permalink 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 {
2022-09-08 12:26:25 +00: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 11:46:49 +00:00
}
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
}