aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-04-15 14:42:08 +0200
committerAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-04-15 14:42:08 +0200
commitbeb0ea0ca44c96083a2ba2f683accc68ad30f1b1 (patch)
tree2934db973f4719d1673b3c69f14f5506e7eacd19 /config
parent48ca185105988aba0626850bf133ba364edd835e (diff)
feat(config): base of guild config
Diffstat (limited to 'config')
-rw-r--r--config/guild.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/config/guild.go b/config/guild.go
new file mode 100644
index 0000000..ddeb300
--- /dev/null
+++ b/config/guild.go
@@ -0,0 +1,42 @@
+package config
+
+import (
+ "github.com/anhgelus/gokord"
+ "gorm.io/gorm"
+)
+
+type GuildConfig struct {
+ gorm.Model
+ GuildID string `gorm:"not null"`
+ XpRoles []XpRole
+}
+
+type XpRole struct {
+ gorm.Model
+ XP uint
+ RoleID string
+ GuildConfigID uint
+}
+
+func GetGuildConfig(guildID string) *GuildConfig {
+ cfg := GuildConfig{GuildID: guildID}
+ return cfg.Load()
+}
+
+func (cfg *GuildConfig) Load() *GuildConfig {
+ gokord.DB.Where("guild_id = ?", cfg.GuildID).Preload("XpRoles").FirstOrCreate(cfg)
+ return cfg
+}
+
+func (cfg *GuildConfig) Save() {
+ gokord.DB.Save(cfg)
+}
+
+func (cfg *GuildConfig) FindXpRole(xp uint, roleID string) (int, *XpRole) {
+ for i, r := range cfg.XpRoles {
+ if r.XP == xp && r.RoleID == roleID {
+ return i, &r
+ }
+ }
+ return 0, nil
+}