feat(top): implements new kind of tops
This commit is contained in:
parent
799df74fcd
commit
01bafe9bf1
7 changed files with 179 additions and 58 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue