Browse Source

fix config parsing order

This resolves an issue where the bot would load configs out of order.
main
Michael Parker 1 year ago
parent
commit
d91f418131
  1. 36
      config.go

36
config.go

@ -9,7 +9,6 @@ import (
"os"
"path"
"path/filepath"
"sort"
"strings"
"github.com/fsnotify/fsnotify"
@ -40,11 +39,12 @@ func initConfig(confDir string) (err error) {
return nil
}
// sort files to load correctly
Log.Debugf("Sorting files")
sort.SliceStable(files.Files, func(i, j int) bool {
return files.Files[i].Location > files.Files[j].Location
})
Log.Debug(files)
// sort all files to load in the correct order.
files = fileSort()
Log.Debug(files)
// for all files pass it to fsnotify.
Log.Debugf("loading files into file watcher")
@ -61,6 +61,30 @@ func initConfig(confDir string) (err error) {
return nil
}
func fileSort() (newFiles confFiles) {
// sort bot config
for _, file := range files.Files {
if file.Context == "conf" {
newFiles.Files = append(newFiles.Files, file)
}
}
// sort server config
for _, file := range files.Files {
if file.Context == "botConf" {
newFiles.Files = append(newFiles.Files, file)
}
}
// sort channel config
for _, file := range files.Files {
if file.Context == "serverConf" {
newFiles.Files = append(newFiles.Files, file)
}
}
return
}
func loadConfDirs(confdir string) (err error) {
cleanConfDir := path.Clean(confdir)

Loading…
Cancel
Save