From 89b23632f5ceeebd82132210c1407dc9514a547b Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Sat, 7 Mar 2026 13:20:56 +0100 Subject: feat(gokord): replace snowflake by uint --- config/xp_role.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'config/xp_role.go') 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{ -- cgit v1.2.3