aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-03-07 13:20:56 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-03-07 13:29:46 +0100
commit89b23632f5ceeebd82132210c1407dc9514a547b (patch)
tree647782dc5f1b1148893c10bc8b3e712b6ea8362b /config
parent9da4d0379b10da8b33563dcd280aa2a9586aa3fb (diff)
feat(gokord): replace snowflake by uintrefactor/leave-old-gokord
Diffstat (limited to 'config')
-rw-r--r--config/channel.go9
-rw-r--r--config/guild.go23
-rw-r--r--config/xp_role.go17
3 files changed, 32 insertions, 17 deletions
diff --git a/config/channel.go b/config/channel.go
index 4650e15..5cc88aa 100644
--- a/config/channel.go
+++ b/config/channel.go
@@ -2,6 +2,7 @@ package config
import (
"context"
+ "strconv"
"strings"
"github.com/nyttikord/gokord/bot"
@@ -21,9 +22,13 @@ const (
func HandleModifyFallbackChannel(ctx context.Context, dg bot.Session, i *interaction.MessageComponent) bool {
cfg := GetGuildConfig(ctx, i.GuildID)
- var channelID string
+ var channelID uint64
if len(i.Data.Values) > 0 {
- channelID = i.Data.Values[0]
+ var err error
+ channelID, err = strconv.ParseUint(i.Data.Values[0], 10, 64)
+ if err != nil {
+ panic(err)
+ }
}
cfg.FallbackChannel = channelID
err := cfg.Save(ctx)
diff --git a/config/guild.go b/config/guild.go
index 6c46a1a..bcebd65 100644
--- a/config/guild.go
+++ b/config/guild.go
@@ -2,6 +2,7 @@ package config
import (
"context"
+ "fmt"
"strings"
"git.anhgelus.world/anhgelus/les-copaings-bot/common"
@@ -11,19 +12,19 @@ import (
type Guild struct {
ID uint `gorm:"primarykey"`
- GuildID string `gorm:"not null;unique"`
+ GuildID uint64 `gorm:"not null;unique"`
XpRoles []XpRole `gorm:"foreignKey:GuildConfigID"`
DisabledChannels string
- FallbackChannel string
+ FallbackChannel uint64
DaysXPRemains uint `gorm:"default:90"` // 30 * 3 = 90 (three months)
RrMessages []RoleReactMessage
}
type RoleReactMessage struct {
ID uint `gorm:"primarykey"`
- MessageID string `gorm:"not null;unique"`
- ChannelID string
- GuildID string
+ MessageID uint64 `gorm:"not null;unique"`
+ ChannelID uint64
+ GuildID uint64
Note string
Roles []*RoleReact
GuildConfigID uint
@@ -32,12 +33,12 @@ type RoleReactMessage struct {
type RoleReact struct {
ID uint `gorm:"primarykey"`
Reaction string
- RoleID string
+ RoleID uint64
RoleReactMessageID uint
CounterID uint `gorm:"-"`
}
-func GetGuildConfig(ctx context.Context, guildID string) *Guild {
+func GetGuildConfig(ctx context.Context, guildID uint64) *Guild {
cfg := Guild{GuildID: guildID}
if err := cfg.Load(ctx); err != nil {
panic(err)
@@ -53,10 +54,10 @@ func (cfg *Guild) Save(ctx context.Context) error {
return common.GetDB(ctx).Save(cfg).Error
}
-func (cfg *Guild) IsDisabled(ctx context.Context, dg bot.Session, channelID string) bool {
+func (cfg *Guild) IsDisabled(ctx context.Context, dg bot.Session, channelID uint64) bool {
ok := true
- for channelID != "" && ok {
- ok = !strings.Contains(cfg.DisabledChannels, channelID)
+ for channelID != 0 && ok {
+ ok = !strings.Contains(cfg.DisabledChannels, fmt.Sprintf("%d", channelID))
c, err := dg.ChannelState().GetChannel(channelID)
if err != nil {
bot.Logger(ctx).Error("unable to find channel %s in state", "error", err, "channel", c)
@@ -74,7 +75,7 @@ func (cfg *Guild) IsDisabled(ctx context.Context, dg bot.Session, channelID stri
return !ok
}
-func (cfg *Guild) FindXpRole(roleID string) (int, *XpRole) {
+func (cfg *Guild) FindXpRole(roleID uint64) (int, *XpRole) {
for i, r := range cfg.XpRoles {
if r.RoleID == roleID {
return i, &r
diff --git a/config/xp_role.go b/config/xp_role.go
index e00d3f7..6592ac9 100644
--- a/config/xp_role.go
+++ b/config/xp_role.go
@@ -19,7 +19,7 @@ import (
type XpRole struct {
ID uint `gorm:"primarykey"`
XP uint
- RoleID string
+ RoleID uint64
GuildConfigID uint
}
@@ -189,7 +189,11 @@ func HandleXpRoleEdit(ctx context.Context, dg bot.Session, i *interaction.Intera
func HandleXpRoleEditRole(ctx context.Context, dg bot.Session, i *interaction.MessageComponent, params *XpRoleId) {
id := params.ID
- role := i.Data.Values[0]
+ role, err := strconv.ParseUint(i.Data.Values[0], 10, 64)
+ if err != nil {
+ // panic because must ensure that the role is valid before
+ panic(err)
+ }
cfg := GetGuildConfig(ctx, i.GuildID)
_, xpRole := cfg.FindXpRoleID(id)
if xpRole == nil {
@@ -206,7 +210,7 @@ func HandleXpRoleEditRole(ctx context.Context, dg bot.Session, i *interaction.Me
return
}
xpRole.RoleID = role
- err := common.GetDB(ctx).Save(xpRole).Error
+ err = common.GetDB(ctx).Save(xpRole).Error
if err != nil {
bot.Logger(ctx).Error("saving config", "error", err, "guild", i.GuildID, "id", id, "type", "add")
}
@@ -340,7 +344,12 @@ func HandleXpRoleAdd(ctx context.Context, dg bot.Session, i *interaction.ModalSu
}
xp := exp.LevelXP(uint(in))
- roleId := i.Data.Components[1].(*component.Label).Component.(*component.SelectMenu).Values[0]
+ rawRoleId := i.Data.Components[1].(*component.Label).Component.(*component.SelectMenu).Values[0]
+ roleId, err := strconv.ParseUint(rawRoleId, 10, 64)
+ if err != nil {
+ // panic because select menu must ensure that the value is valid
+ panic(err)
+ }
cfg := GetGuildConfig(ctx, i.GuildID)
cfg.XpRoles = append(cfg.XpRoles, XpRole{