From 42dbee08c0f4218d0b57557d37100adb66132387 Mon Sep 17 00:00:00 2001 From: Dylan Maassen van den Brink Date: Mon, 19 Feb 2024 17:35:05 +0100 Subject: [PATCH 1/2] Made root command variable, fix loading order for customizations --- bot.go | 7 +++---- internal/utils/customization.go | 9 ++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bot.go b/bot.go index 6d7c0dd..043be41 100644 --- a/bot.go +++ b/bot.go @@ -27,7 +27,7 @@ var ( log = utils.Log unregisterCommands = flag.Bool("unregister", false, "Use this flag to unregister all registered bot commands") debugMode = flag.Bool("debug", false, "Use this flag to enable debug mode") - customs = &utils.BotCustoms + customs = utils.GetCustoms() dc *discordgo.Session err error ) @@ -83,7 +83,7 @@ var ( }, }, { - Name: "tibby", + Name: customs.RootCommand, Description: fmt.Sprintf("General commands for %s", customs.BotName), Options: []*discordgo.ApplicationCommandOption{ { @@ -207,7 +207,7 @@ var ( }, }) }, - "tibby": func(s *discordgo.Session, i *discordgo.InteractionCreate) { + customs.RootCommand: func(s *discordgo.Session, i *discordgo.InteractionCreate) { options := i.ApplicationCommandData().Options switch options[0].Name { @@ -262,7 +262,6 @@ func init() { } else { log.Debug("Loaded .env file(s)") } - utils.LoadCustoms() } func main() { diff --git a/internal/utils/customization.go b/internal/utils/customization.go index efe06ff..12f1e1a 100644 --- a/internal/utils/customization.go +++ b/internal/utils/customization.go @@ -15,23 +15,26 @@ type CustomizationOptions struct { } } -var BotCustoms CustomizationOptions - -func LoadCustoms() { +func GetCustoms() CustomizationOptions { customsFile, err := os.Open("customizations/botproperties.json") if err != nil { Log.Error("Couldn't load customizations file: " + err.Error()) os.Exit(1) } + var BotCustoms CustomizationOptions + jsonParser := json.NewDecoder(customsFile) if err = jsonParser.Decode(&BotCustoms); err != nil { Log.Error("Couldn't parse customizations file: " + err.Error()) os.Exit(1) } + + return BotCustoms } func GetCdnUri(fileName string) string { + BotCustoms := GetCustoms() if val, ok := BotCustoms.CDN.Files[fileName]; ok { return BotCustoms.CDN.BaseURL + val } else { From 9701a718ff1afcea24f488c7eef7488985d3b3c3 Mon Sep 17 00:00:00 2001 From: Dylan Maassen van den Brink Date: Mon, 19 Feb 2024 17:36:57 +0100 Subject: [PATCH 2/2] small typo fix --- internal/utils/customization.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/utils/customization.go b/internal/utils/customization.go index 12f1e1a..b144a9f 100644 --- a/internal/utils/customization.go +++ b/internal/utils/customization.go @@ -38,7 +38,7 @@ func GetCdnUri(fileName string) string { if val, ok := BotCustoms.CDN.Files[fileName]; ok { return BotCustoms.CDN.BaseURL + val } else { - Log.Error("Couldn't file an customization entry for the file " + fileName) + Log.Error("Couldn't find an customization entry for the file " + fileName) } return "" }