diff options
| author | Anhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me> | 2024-04-15 14:42:08 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me> | 2024-04-15 14:42:08 +0200 |
| commit | beb0ea0ca44c96083a2ba2f683accc68ad30f1b1 (patch) | |
| tree | 2934db973f4719d1673b3c69f14f5506e7eacd19 /xp | |
| parent | 48ca185105988aba0626850bf133ba364edd835e (diff) | |
feat(config): base of guild config
Diffstat (limited to 'xp')
| -rw-r--r-- | xp/events.go | 6 | ||||
| -rw-r--r-- | xp/member.go | 11 |
2 files changed, 10 insertions, 7 deletions
diff --git a/xp/events.go b/xp/events.go index f6b9bc5..3ce4f06 100644 --- a/xp/events.go +++ b/xp/events.go @@ -21,8 +21,7 @@ const ( ) func OnMessage(s *discordgo.Session, m *discordgo.MessageCreate) { - c := Copaing{DiscordID: m.Author.ID, GuildID: m.GuildID} - c.Load() + c := GetCopaing(m.Author.ID, m.GuildID) // add xp trimmed := utils.TrimMessage(strings.ToLower(m.Content)) c.AddXP(s, XPMessage(uint(len(trimmed)), calcDiversity(trimmed)), func(_ uint, _ uint) { @@ -119,8 +118,7 @@ func onDisconnect(s *discordgo.Session, e *discordgo.VoiceStateUpdate, client *r utils.SendWarn(fmt.Sprintf("User %s spent more than 6 hours in vocal", e.Member.DisplayName())) timeInVocal = MaxTimeInVocal } - c := Copaing{DiscordID: u.DiscordID, GuildID: u.GuildID} - c.Load() + c := GetCopaing(u.DiscordID, u.GuildID) c.AddXP(s, XPVocal(uint(timeInVocal)), func(_ uint, _ uint) { //TODO: handle new level in vocal }) diff --git a/xp/member.go b/xp/member.go index 578e533..280b9e0 100644 --- a/xp/member.go +++ b/xp/member.go @@ -10,13 +10,18 @@ import ( type Copaing struct { gorm.Model - DiscordID string - XP uint - GuildID string + DiscordID string `gorm:"not null"` + XP uint `gorm:"default:0"` + GuildID string `gorm:"not null"` } var r *redis.Client +func GetCopaing(discordID string, guildID string) *Copaing { + c := Copaing{DiscordID: discordID, GuildID: guildID} + return c.Load() +} + func (c *Copaing) Load() *Copaing { gokord.DB.Where("discord_id = ? and guild_id = ?", c.DiscordID, c.GuildID).FirstOrCreate(c) return c |
