Skip to content

Commit

Permalink
Discord: Try to avoid more race conditions
Browse files Browse the repository at this point in the history
also added RACE=on to Makefile to enable go's race detector.
  • Loading branch information
hrfee committed May 23, 2021
1 parent f419a57 commit 86ef665
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ else
TYPECHECK :=
endif

RACE ?= off
ifeq ($(RACE), on)
RACEDETECTOR := -race
else
RACEDETECTOR :=
endif

npm:
$(info installing npm dependencies)
npm install
Expand Down Expand Up @@ -91,7 +98,7 @@ compile:
$(GOBINARY) mod download
$(info Building)
mkdir -p build
$(GOBINARY) build -ldflags="$(LDFLAGS)" $(TAGS) -o build/jfa-go
$(GOBINARY) build $(RACEDETECTOR) -ldflags="$(LDFLAGS)" $(TAGS) -o build/jfa-go

compress:
upx --lzma build/jfa-go
Expand Down
8 changes: 7 additions & 1 deletion discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ func (d *DiscordDaemon) run() {
d.app.err.Printf("Discord: Failed to start daemon: %v", err)
return
}
// Sometimes bot.State isn't populated quick enough
// Wait for everything to populate, it's slow sometimes.
for d.bot.State == nil {
continue
}
for d.bot.State.User == nil {
continue
}
d.username = d.bot.State.User.Username
for d.bot.State.Guilds == nil {
continue
}
// Choose the last guild (server), for now we don't really support multiple anyway
d.guildID = d.bot.State.Guilds[len(d.bot.State.Guilds)-1].ID
guild, err := d.bot.Guild(d.guildID)
Expand Down

0 comments on commit 86ef665

Please sign in to comment.