Skip to content

Commit

Permalink
Merge pull request #33 from TibbyRocks/feature/fix-customs-loading
Browse files Browse the repository at this point in the history
Made root command variable, fix loading order for customizations
  • Loading branch information
mozoarella authored Feb 19, 2024
2 parents 19d2200 + 9701a71 commit 98423b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 3 additions & 4 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -83,7 +83,7 @@ var (
},
},
{
Name: "tibby",
Name: customs.RootCommand,
Description: fmt.Sprintf("General commands for %s", customs.BotName),
Options: []*discordgo.ApplicationCommandOption{
{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -262,7 +262,6 @@ func init() {
} else {
log.Debug("Loaded .env file(s)")
}
utils.LoadCustoms()
}

func main() {
Expand Down
11 changes: 7 additions & 4 deletions internal/utils/customization.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,30 @@ 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 {
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 ""
}

0 comments on commit 98423b3

Please sign in to comment.