1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 09:00:10 +00:00

Discord: Try to avoid more race conditions

also added RACE=on to Makefile to enable go's race detector.
This commit is contained in:
Harvey Tindall 2021-05-23 22:26:56 +01:00
parent f419a57e6d
commit 86ef665b12
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
2 changed files with 15 additions and 2 deletions

View File

@ -52,6 +52,13 @@ else
TYPECHECK := TYPECHECK :=
endif endif
RACE ?= off
ifeq ($(RACE), on)
RACEDETECTOR := -race
else
RACEDETECTOR :=
endif
npm: npm:
$(info installing npm dependencies) $(info installing npm dependencies)
npm install npm install
@ -91,7 +98,7 @@ compile:
$(GOBINARY) mod download $(GOBINARY) mod download
$(info Building) $(info Building)
mkdir -p build mkdir -p build
$(GOBINARY) build -ldflags="$(LDFLAGS)" $(TAGS) -o build/jfa-go $(GOBINARY) build $(RACEDETECTOR) -ldflags="$(LDFLAGS)" $(TAGS) -o build/jfa-go
compress: compress:
upx --lzma build/jfa-go upx --lzma build/jfa-go

View File

@ -77,11 +77,17 @@ func (d *DiscordDaemon) run() {
d.app.err.Printf("Discord: Failed to start daemon: %v", err) d.app.err.Printf("Discord: Failed to start daemon: %v", err)
return return
} }
// Sometimes bot.State isn't populated quick enough // Wait for everything to populate, it's slow sometimes.
for d.bot.State == nil { for d.bot.State == nil {
continue continue
} }
for d.bot.State.User == nil {
continue
}
d.username = d.bot.State.User.Username 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 // 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 d.guildID = d.bot.State.Guilds[len(d.bot.State.Guilds)-1].ID
guild, err := d.bot.Guild(d.guildID) guild, err := d.bot.Guild(d.guildID)