2020-06-09 13:04:44 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
|
|
|
)
|
|
|
|
|
|
|
|
var defaultConfig = []byte("")
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Token string `toml:"token"`
|
|
|
|
Prefix string `toml:"prefix"`
|
|
|
|
MCMToken string `toml:"mcm_token"`
|
|
|
|
MCMURL string `toml:"mcm_url"`
|
|
|
|
DBPath string `toml:"db_path"`
|
|
|
|
|
|
|
|
StaffRoles []string `toml:"staff_roles"`
|
2020-06-12 16:38:18 +00:00
|
|
|
Echoes []Echo `toml:"echoes"`
|
2020-06-09 13:04:44 +00:00
|
|
|
MessageRoles []MessageRole `toml:"message_roles"`
|
|
|
|
RegisterRole string `toml:"register_role"`
|
|
|
|
RegisteredChannel string `toml:"registered_channel"`
|
|
|
|
FiredRole string `toml:"fired_role"`
|
2020-07-02 20:00:22 +00:00
|
|
|
MemeRate string `toml:"meme_rate"`
|
|
|
|
Insult struct {
|
|
|
|
Targets []string `toml:"targets"`
|
|
|
|
Comparisons []string `toml:"comparisons"`
|
|
|
|
Adjectives []string `toml:"adjectives"`
|
|
|
|
Nouns []string `toml:"nouns"`
|
|
|
|
} `toml:"insult"`
|
2020-07-02 21:52:20 +00:00
|
|
|
Compliment struct {
|
|
|
|
Verbs []string `toml:"verbs"`
|
|
|
|
Nouns []string `toml:"nouns"`
|
|
|
|
MinorThings []string `toml:"minor_things"`
|
|
|
|
} `toml:"compliment"`
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type MessageRole struct {
|
2020-06-12 05:17:58 +00:00
|
|
|
ChannelID string `toml:"channel_id"`
|
2020-06-09 13:04:44 +00:00
|
|
|
MessageID string `toml:"message_id"`
|
|
|
|
RoleID string `toml:"role_id"`
|
|
|
|
Emoji string `toml:"emoji"`
|
|
|
|
}
|
|
|
|
|
2020-06-12 16:38:18 +00:00
|
|
|
type Echo struct {
|
2020-06-09 13:04:44 +00:00
|
|
|
Name string `toml:"name"`
|
|
|
|
Aliases []string `toml:"aliases"`
|
2020-06-12 16:38:18 +00:00
|
|
|
Message string `toml:"message"`
|
|
|
|
Help string `toml:"help"`
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Load(configPath string) (*Config, error) {
|
|
|
|
var err error
|
|
|
|
var configContent []byte
|
|
|
|
if len(configPath) == 0 {
|
|
|
|
configPath = "sedbot.toml"
|
|
|
|
}
|
|
|
|
|
|
|
|
configContent, err = ioutil.ReadFile(configPath)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
if err = ioutil.WriteFile(configPath, defaultConfig, os.ModePerm); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
configContent = defaultConfig
|
|
|
|
} else {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var cfg *Config
|
|
|
|
if err = toml.Unmarshal(configContent, &cfg); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg, nil
|
|
|
|
}
|