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
This commit is contained in:
Gary Kramlich
2022-04-14 18:57:54 -05:00
parent 7ec86340c3
commit 619dd9aef8

View File

@@ -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()
}