2017-10-04 17:56:18 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
2017-11-14 03:44:21 +04:00
|
|
|
|
"gopkg.in/yaml.v2"
|
2017-10-18 07:03:34 +04:00
|
|
|
|
"io/ioutil"
|
2017-11-22 16:32:10 +04:00
|
|
|
|
"lab.pztrn.name/golibs/mogrus"
|
2017-10-18 07:03:34 +04:00
|
|
|
|
"path/filepath"
|
2017-10-04 17:56:18 +04:00
|
|
|
|
)
|
|
|
|
|
|
2017-12-23 01:40:36 +04:00
|
|
|
|
// VERSION is the current bot's version
|
|
|
|
|
const VERSION = "0.6.5"
|
2017-10-04 17:56:18 +04:00
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
// DatabaseConnection handles database connection settings in config.yaml
|
2017-10-04 17:56:18 +04:00
|
|
|
|
type DatabaseConnection struct {
|
2017-10-18 07:03:34 +04:00
|
|
|
|
Host string `yaml:"host"`
|
|
|
|
|
Port string `yaml:"port"`
|
|
|
|
|
User string `yaml:"user"`
|
|
|
|
|
Password string `yaml:"password"`
|
|
|
|
|
Database string `yaml:"database"`
|
2017-10-04 17:56:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
// TelegramConnection handles settings for Telegram connection in config.yaml
|
2017-10-04 17:56:18 +04:00
|
|
|
|
type TelegramConnection struct {
|
2017-10-18 07:03:34 +04:00
|
|
|
|
APIToken string `yaml:"api_token"`
|
2017-10-04 17:56:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-26 16:54:06 +04:00
|
|
|
|
// SpecialChats handles settings for special chats
|
|
|
|
|
type SpecialChats struct {
|
2017-12-23 17:03:26 +04:00
|
|
|
|
AcademyID string `yaml:"academy_id"`
|
2017-11-26 16:54:06 +04:00
|
|
|
|
BastionID string `yaml:"bastion_id"`
|
|
|
|
|
DefaultID string `yaml:"default_id"`
|
|
|
|
|
HeadquartersID string `yaml:"headquarters_id"`
|
2017-11-13 22:51:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 03:44:21 +04:00
|
|
|
|
// LoggingConfig handles log file configuration
|
|
|
|
|
type LoggingConfig struct {
|
|
|
|
|
LogPath string `yaml:"log_path"`
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
// Config is a struct which represents config.yaml structure
|
2017-10-04 17:56:18 +04:00
|
|
|
|
type Config struct {
|
2017-11-26 16:54:06 +04:00
|
|
|
|
Telegram TelegramConnection `yaml:"telegram_connection"`
|
|
|
|
|
Database DatabaseConnection `yaml:"database_connection"`
|
|
|
|
|
SpecialChats SpecialChats `yaml:"special_chats"`
|
|
|
|
|
Logs LoggingConfig `yaml:"logs"`
|
2017-10-04 17:56:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
// Init is a configuration initializer
|
2017-11-22 16:32:10 +04:00
|
|
|
|
func (c *Config) Init(log *mogrus.LoggerHandler, configPath string) {
|
|
|
|
|
fname, _ := filepath.Abs(configPath)
|
2017-10-18 07:03:34 +04:00
|
|
|
|
yamlFile, yerr := ioutil.ReadFile(fname)
|
|
|
|
|
if yerr != nil {
|
|
|
|
|
log.Fatal("Can't read config file")
|
2017-11-22 16:32:10 +04:00
|
|
|
|
} else {
|
|
|
|
|
log.Info("Using " + configPath + " as config file.")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yperr := yaml.Unmarshal(yamlFile, c)
|
|
|
|
|
if yperr != nil {
|
|
|
|
|
log.Fatal("Can't parse config file")
|
|
|
|
|
}
|
2017-10-04 17:56:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
// New creates new empty Config object
|
2017-10-04 17:56:18 +04:00
|
|
|
|
func New() *Config {
|
2017-10-18 07:03:34 +04:00
|
|
|
|
c := &Config{}
|
|
|
|
|
return c
|
2017-10-04 17:56:18 +04:00
|
|
|
|
}
|