Эх сурвалжийг харах

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
Gary Kramlich 3 жил өмнө
parent
commit
619dd9aef8
1 өөрчлөгдсөн 9 нэмэгдсэн , 0 устгасан
  1. 9 0
      bridge/user.go

+ 9 - 0
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()
 }