diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-07 13:20:56 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-07 13:29:46 +0100 |
| commit | 89b23632f5ceeebd82132210c1407dc9514a547b (patch) | |
| tree | 647782dc5f1b1148893c10bc8b3e712b6ea8362b /user | |
| parent | 9da4d0379b10da8b33563dcd280aa2a9586aa3fb (diff) | |
feat(gokord): replace snowflake by uintrefactor/leave-old-gokord
Diffstat (limited to 'user')
| -rw-r--r-- | user/member.go | 8 | ||||
| -rw-r--r-- | user/state.go | 13 | ||||
| -rw-r--r-- | user/xp.go | 2 |
3 files changed, 12 insertions, 11 deletions
diff --git a/user/member.go b/user/member.go index e3a1d30..db39911 100644 --- a/user/member.go +++ b/user/member.go @@ -9,16 +9,16 @@ import ( type Copaing struct { ID uint `gorm:"primarykey"` - DiscordID string `gorm:"not null"` + DiscordID uint64 `gorm:"not null"` CopaingXPs []CopaingXP `gorm:"constraint:OnDelete:SET NULL;"` - GuildID string `gorm:"not null"` + GuildID uint64 `gorm:"not null"` } type CopaingXP struct { ID uint `gorm:"primarykey"` XP uint `gorm:"default:0"` CopaingID uint - GuildID string `gorm:"not null;"` + GuildID uint64 `gorm:"not null;"` CreatedAt time.Time } @@ -27,7 +27,7 @@ type CopaingAccess interface { GetXP() uint } -func GetCopaing(ctx context.Context, discordID string, guildID string) *CopaingCached { +func GetCopaing(ctx context.Context, discordID, guildID uint64) *CopaingCached { state := GetState(ctx) cc, err := state.Copaing(guildID, discordID) if err != nil { diff --git a/user/state.go b/user/state.go index d1f84b5..9f1c90e 100644 --- a/user/state.go +++ b/user/state.go @@ -3,6 +3,7 @@ package user import ( "context" "errors" + "fmt" "math" "sync" "time" @@ -22,8 +23,8 @@ type XPCached struct { type CopaingCached struct { ID uint - DiscordID string - GuildID string + DiscordID uint64 + GuildID uint64 XP uint XPs []XPCached XPToAdd uint @@ -130,8 +131,8 @@ func KeyCopaingCached(c *Copaing) string { return KeyCopaingCachedRaw(c.GuildID, c.DiscordID) } -func KeyCopaingCachedRaw(guildID, copaingID string) string { - return guildID + ":" + copaingID +func KeyCopaingCachedRaw(guildID, copaingID uint64) string { + return fmt.Sprintf("%d:%d", guildID, copaingID) } type State struct { @@ -176,7 +177,7 @@ func deepCopy(src CopaingCached) CopaingCached { return res } -func (s *State) Copaing(guildID, copaingID string) (*CopaingCached, error) { +func (s *State) Copaing(guildID, copaingID uint64) (*CopaingCached, error) { s.mu.RLock() defer s.mu.RUnlock() @@ -187,7 +188,7 @@ func (s *State) Copaing(guildID, copaingID string) (*CopaingCached, error) { return &c, nil } -func (s *State) Copaings(guild string) []CopaingCached { +func (s *State) Copaings(guild uint64) []CopaingCached { s.mu.RLock() defer s.mu.RUnlock() @@ -54,7 +54,7 @@ func (cc *CopaingCached) GetXPForDays(d int) uint { } // GetBestXP returns n Copaings with the best XP within d days (d <= cfg.DaysXPRemain; d < 0 <=> d = cfg.DaysXPRemain) -func GetBestXP(ctx context.Context, guildId string, n uint, d int) []CopaingCached { +func GetBestXP(ctx context.Context, guildId uint64, n uint, d int) []CopaingCached { ccs := GetState(ctx).Copaings(guildId) if d > 0 { for i, cc := range ccs { |
