From 619dd9aef83656552511d4485655e130e2151c46 Mon Sep 17 00:00:00 2001 From: Gary Kramlich Date: Thu, 14 Apr 2022 18:57:54 -0500 Subject: [PATCH] Fix a bug where guilds weren't being saved During a refactor the guild.Upsert somehow got removed and I didn't notice it because my test account was synced. So to avoid this in the future we output the number of guilds the database knows, the number discord says we have and then how many the database has after we purge guilds the user has left. refs #8 --- bridge/user.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bridge/user.go b/bridge/user.go index f34102e..1dcb262 100644 --- a/bridge/user.go +++ b/bridge/user.go @@ -412,6 +412,9 @@ func (u *User) readyHandler(s *discordgo.Session, r *discordgo.Ready) { // build a list of the current guilds we're in so we can prune the old ones current := []string{} + u.log.Debugln("database guild count", len(u.guilds)) + u.log.Debugln("discord guild count", len(r.Guilds)) + for _, guild := range r.Guilds { current = append(current, guild.ID) @@ -425,6 +428,8 @@ func (u *User) readyHandler(s *discordgo.Session, r *discordgo.Ready) { if !guild.Unavailable { u.guilds[guild.ID].GuildName = guild.Name } + + val.Upsert() } else { g := u.bridge.db.Guild.New() g.DiscordID = u.ID @@ -434,6 +439,8 @@ func (u *User) readyHandler(s *discordgo.Session, r *discordgo.Ready) { if !guild.Unavailable { g.GuildName = guild.Name } + + g.Upsert() } } @@ -444,6 +451,8 @@ func (u *User) readyHandler(s *discordgo.Session, r *discordgo.Ready) { // anymore. u.loadGuilds() + u.log.Debugln("updated database guild count", len(u.guilds)) + u.Update() }