diff options
Diffstat (limited to 'config')
| -rw-r--r-- | config/guild.go | 8 | ||||
| -rw-r--r-- | config/redis.go | 28 |
2 files changed, 32 insertions, 4 deletions
diff --git a/config/guild.go b/config/guild.go index 242cc89..fb7eaef 100644 --- a/config/guild.go +++ b/config/guild.go @@ -3,20 +3,20 @@ package config import ( "github.com/anhgelus/gokord" "github.com/anhgelus/gokord/utils" - "gorm.io/gorm" "strings" ) type GuildConfig struct { - gorm.Model - GuildID string `gorm:"not null"` + ID uint `gorm:"primarykey"` + GuildID string `gorm:"not null;unique"` XpRoles []XpRole DisabledChannels string FallbackChannel string + DaysXPRemains uint `gorm:"default:90"` // 30 * 3 = 90 (three months) } type XpRole struct { - gorm.Model + ID uint `gorm:"primarykey"` XP uint RoleID string GuildConfigID uint diff --git a/config/redis.go b/config/redis.go new file mode 100644 index 0000000..bfec5a0 --- /dev/null +++ b/config/redis.go @@ -0,0 +1,28 @@ +package config + +import ( + "github.com/anhgelus/gokord" + "github.com/anhgelus/gokord/utils" + "github.com/redis/go-redis/v9" +) + +var redisClient *redis.Client + +func GetRedisClient() (*redis.Client, error) { + if redisClient == nil { + var err error + redisClient, err = gokord.BaseCfg.GetRedisCredentials().Connect() + return redisClient, err + } + return redisClient, nil +} + +func CloseRedisClient() { + if redisClient == nil { + return + } + err := redisClient.Close() + if err != nil { + utils.SendAlert("config/redis.go - Closing redis client", err.Error()) + } +} |
