diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-07 13:20:56 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-07 13:29:46 +0100 |
| commit | 89b23632f5ceeebd82132210c1407dc9514a547b (patch) | |
| tree | 647782dc5f1b1148893c10bc8b3e712b6ea8362b /config/xp_role.go | |
| parent | 9da4d0379b10da8b33563dcd280aa2a9586aa3fb (diff) | |
feat(gokord): replace snowflake by uintrefactor/leave-old-gokord
Diffstat (limited to 'config/xp_role.go')
| -rw-r--r-- | config/xp_role.go | 17 |
1 files changed, 13 insertions, 4 deletions
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{ |
