aboutsummaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-03-08 18:51:05 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-03-08 18:51:05 +0100
commit6e92feaba23a4992e0ec4b529660921a6bcb492a (patch)
tree05024b52d4c8ede041facdc48ac65af5ba0259da /user
parent3bcf74c47d1597ba650dc5a55868f83f5f547ad7 (diff)
feat(config): leave gorm
Diffstat (limited to 'user')
-rw-r--r--user/level.go4
-rw-r--r--user/member.go9
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