aboutsummaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
Diffstat (limited to 'user')
-rw-r--r--user/member.go8
-rw-r--r--user/state.go13
-rw-r--r--user/xp.go2
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()
diff --git a/user/xp.go b/user/xp.go
index d2b7ca6..dad7865 100644
--- a/user/xp.go
+++ b/user/xp.go
@@ -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 {