Fix: Prevent activating duplicate module ID

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-08-26 00:31:20 +02:00
parent 35888b0abd
commit 49ce944d30
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -11,6 +11,7 @@ import (
log "github.com/sirupsen/logrus"
httpHelpers "github.com/Luzifer/go_helpers/v2/http"
"github.com/Luzifer/go_helpers/v2/str"
"github.com/Luzifer/rconfig/v2"
)
@ -73,6 +74,7 @@ func main() {
discord.Identify.Intents = discordgo.IntentsAll
var activeIDs []string
for i, mc := range config.ModuleConfigs {
logger := log.WithFields(log.Fields{
"id": mc.ID,
@ -80,6 +82,11 @@ func main() {
"module": mc.Type,
})
if str.StringInSlice(mc.ID, activeIDs) {
logger.Error("Found duplicate module ID, module will be disabled")
continue
}
if mc.ID == "" {
logger.Error("Module contains no ID and will be disabled")
continue
@ -95,6 +102,7 @@ func main() {
}
activeModules = append(activeModules, mod)
activeIDs = append(activeIDs, mc.ID)
logger.Debug("Enabled module")
}