Skip to content

Commit

Permalink
Merge pull request #20 from TibbyRocks/bugfix/fix-logging
Browse files Browse the repository at this point in the history
Fix logging in the utils package for real this time
  • Loading branch information
mozoarella authored Feb 17, 2024
2 parents 598d6e4 + efb7ad4 commit 97596d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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.BotCustoms
dc *discordgo.Session
err error
)
Expand Down Expand Up @@ -193,10 +193,10 @@ func init() {
} else {
log.Debug("Loaded .env file(s)")
}
utils.LoadCustoms()
}

func main() {

log.Info("Starting " + customs.BotName)

setupDiscordSession()
Expand Down
11 changes: 6 additions & 5 deletions internal/utils/customization.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ type CustomizationOptions struct {
}

var BotCustoms CustomizationOptions
var log = Log

func init() {
func LoadCustoms() {
customsFile, err := os.Open("customizations/botproperties.json")
if err != nil {
log.Error("Couldn't load customizations file: " + err.Error())
Log.Error("Couldn't load customizations file: " + err.Error())
os.Exit(1)
}

jsonParser := json.NewDecoder(customsFile)
if err = jsonParser.Decode(&BotCustoms); err != nil {
log.Error("Couldn't parse customizations file: " + err.Error())
Log.Error("Couldn't parse customizations file: " + err.Error())
os.Exit(1)
}
}

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 file an customization entry for the file " + fileName)
}
return ""
}
4 changes: 2 additions & 2 deletions internal/utils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func FileToSlice(inputFile string) []string {
var lines []string
file, err := os.Open(inputFile)
if err != nil {
log.Error(err.Error())
Log.Error(err.Error())
}
defer file.Close()

Expand All @@ -19,7 +19,7 @@ func FileToSlice(inputFile string) []string {
}

if err := scanner.Err(); err != nil {
log.Error(err.Error())
Log.Error(err.Error())
}

return lines
Expand Down

0 comments on commit 97596d9

Please sign in to comment.