diff options
Diffstat (limited to 'user')
| -rw-r--r-- | user/level.go | 4 | ||||
| -rw-r--r-- | user/member.go | 9 |
2 files changed, 7 insertions, 6 deletions
diff --git a/user/level.go b/user/level.go index 26cf03f..d068f97 100644 --- a/user/level.go +++ b/user/level.go @@ -15,7 +15,7 @@ import ( ) func onNewLevel(ctx context.Context, dg bot.Session, m *user.Member, level uint) { - cfg := config.GetGuildConfig(ctx, m.GuildID) + cfg := config.GetGuild(ctx, m.GuildID) xpForLevel := exp.LevelXP(level) for _, role := range cfg.XpRoles { if role.XP <= xpForLevel && !slices.Contains(m.Roles, role.RoleID) { @@ -60,7 +60,7 @@ func PeriodicReducer(ctx context.Context, dg bot.Session) { n := 0 var wg sync.WaitGroup for _, g := range dg.GuildState().ListGuilds() { - cfg := config.GetGuildConfig(ctx, g) + cfg := config.GetGuild(ctx, g) res, err := common.GetDB(ctx).ExecContext( ctx, `DELETE FROM copaing_xps WHERE guild_id = ? and created_at < ?`, diff --git a/user/member.go b/user/member.go index 1e25617..3437be1 100644 --- a/user/member.go +++ b/user/member.go @@ -11,15 +11,15 @@ import ( type Copaing struct { ID uint64 - CopaingXPs []CopaingXP `gorm:"constraint:OnDelete:SET NULL;"` - GuildID uint64 `gorm:"not null"` + CopaingXPs []CopaingXP + GuildID uint64 lastSaved int } type CopaingXP struct { - XP uint `gorm:"default:0"` + XP uint CopaingID uint64 - GuildID uint64 `gorm:"not null;"` + GuildID uint64 CreatedAt time.Time } @@ -67,6 +67,7 @@ func (c *Copaing) load(ctx context.Context) error { `SELECT xp, created_at FROM copaing_xps WHERE copaing_id = ? AND guild_id = ?`, c.ID, c.GuildID, ) + defer rows.Close() if err != nil { if !errors.Is(err, sql.ErrNoRows) { return err |
