Skip to content
Snippets Groups Projects
Select Git revision
  • 05558cdf808e2979d649e8bed3e13b7fa9c62f1c
  • master default protected
2 results

config.go

Blame
  • config.go 2.99 KiB
    package main
    
    import (
    	"flag"
    	"github.com/pelletier/go-toml/v2"
    	"log"
    	"os"
    	"strconv"
    )
    
    var (
    	config   conf
    	confPath string
    	parsed   = false
    
    	discordBridge  = make(map[string]bridgeConf)
    	telegramBridge = make(map[int64]bridgeConf)
    )
    
    func init() {
    	flag.StringVar(&confPath, "c", "bridge.conf", "specify location of configuration file")
    }
    
    type conf struct {
    	System   systemConf
    	Telegram telegramConf
    	Discord  discordConf
    	Bridges  struct{ Item []bridgeConf }
    }
    
    type systemConf struct {
    	Verbose        bool
    	DisplaceHeader bool
    }
    
    type telegramConf struct {
    	Token         string
    	NameFormat    string
    	StickerEmoji  bool
    	BypassBacklog bool
    }
    
    type discordConf struct {
    	Token       string
    	NameFormat  string
    	StickerText bool
    }
    
    type bridgeConf struct {
    	Label    string
    	Discord  bridgePlatformConf
    	Telegram bridgePlatformConf
    }
    
    type bridgePlatformConf struct {
    	ID     int
    	Enable bool
    	Join   bool
    	Leave  bool
    	Delete bool
    }
    
    func setupConfig() {
    	if parsed {
    		panic("config already parsed")
    	}
    	defer func() { parsed = true }()
    
    	if file, err := os.Open(confPath); err != nil {
    		if !os.IsNotExist(err) {