aboutsummaryrefslogtreecommitdiff
path: root/user/member.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-05-13 16:15:47 +0200
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-05-13 16:15:47 +0200
commit01bafe9bf1de5be4e770b9500480807d4973d8d6 (patch)
treec6eafab11fef21c221136019ea490176185cec81 /user/member.go
parent799df74fcda5266fd295b49fc759c605c815cad9 (diff)
feat(top): implements new kind of tops
Diffstat (limited to 'user/member.go')
-rw-r--r--user/member.go30
1 files changed, 5 insertions, 25 deletions
diff --git a/user/member.go b/user/member.go
index b61aa76..cf7c4a4 100644
--- a/user/member.go
+++ b/user/member.go
@@ -4,7 +4,6 @@ import (
"fmt"
"github.com/anhgelus/gokord"
"github.com/anhgelus/gokord/utils"
- "github.com/anhgelus/les-copaings-bot/config"
"time"
)
@@ -23,6 +22,11 @@ type CopaingXP struct {
CreatedAt time.Time
}
+type CopaingAccess interface {
+ ToCopaing() *Copaing
+ GetXP() uint
+}
+
const (
LastEvent = "last_event"
AlreadyRemoved = "already_removed"
@@ -52,30 +56,6 @@ func (c *Copaing) Load() error {
Error
}
-func (c *Copaing) GetXP() (uint, error) {
- cfg := config.GetGuildConfig(c.GuildID)
- xp := uint(0)
- y, m, d := time.Unix(time.Now().Unix()-int64(cfg.DaysXPRemains*24*60*60), 0).Date()
- rows, err := gokord.DB.
- Model(&CopaingXP{}).
- Where(fmt.Sprintf("created_at >= '%d-%d-%d' and guild_id = ? and discord_id = ?", y, m, d), c.GuildID, c.DiscordID).
- Rows()
- defer rows.Close()
- if err != nil {
- return 0, err
- }
- for rows.Next() {
- var cXP CopaingXP
- err = gokord.DB.ScanRows(rows, &cXP)
- if err != nil {
- utils.SendAlert("user/member.go - Scaning rows", err.Error(), "discord_id", c.DiscordID, "guild_id", c.GuildID)
- continue
- }
- xp += cXP.XP
- }
- return xp, nil
-}
-
func (c *Copaing) Save() error {
return gokord.DB.Save(c).Error
}