diff options
Diffstat (limited to 'config/xp_role_events.go')
| -rw-r--r-- | config/xp_role_events.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/config/xp_role_events.go b/config/xp_role_events.go index cda90d5..47026b5 100644 --- a/config/xp_role_events.go +++ b/config/xp_role_events.go @@ -6,6 +6,7 @@ import ( "slices" "strconv" + "git.anhgelus.world/anhgelus/les-copaings-bot/common" "git.anhgelus.world/anhgelus/les-copaings-bot/dynamicid" "git.anhgelus.world/anhgelus/les-copaings-bot/exp" "github.com/nyttikord/gokord/bot" @@ -39,7 +40,7 @@ func HandleXpRole(ctx context.Context, dg bot.Session, i *interaction.Interactio &component.Separator{}, }, } - slices.SortFunc(cfg.XpRoles, func(xp1, xp2 XpRole) int { + slices.SortFunc(cfg.XpRoles, func(xp1, xp2 *XpRole) int { return int(xp2.XP) - int(xp1.XP) }) for _, r := range cfg.XpRoles { @@ -122,7 +123,7 @@ func HandleXpRoleNew(ctx context.Context, dg bot.Session, i *interaction.Message func HandleXpRoleEdit(ctx context.Context, dg bot.Session, i *interaction.Interaction, params *XpRoleId) { config := GetGuild(ctx, i.GuildID) id := params.ID - _, role := config.FindXpRole(id) + role := config.FindXpRole(id) if role == nil { HandleXpRole(ctx, dg, i) return @@ -187,7 +188,7 @@ func HandleXpRoleEditRole(ctx context.Context, dg bot.Session, i *interaction.Me panic(err) } cfg := GetGuild(ctx, i.GuildID) - _, xpRole := cfg.FindXpRole(id) + xpRole := cfg.FindXpRole(id) if xpRole == nil { err := interaction.Respond(i.Interaction, &interaction.Response{ Type: types.InteractionResponseChannelMessageWithSource, @@ -202,7 +203,7 @@ func HandleXpRoleEditRole(ctx context.Context, dg bot.Session, i *interaction.Me return } xpRole.RoleID = role - err = xpRole.Save(ctx) + err = xpRole.Save(ctx, common.GetDB(ctx)) if err != nil { bot.Logger(ctx).Error("saving config", "error", err, "guild", i.GuildID, "id", id, "type", "add") } @@ -212,7 +213,7 @@ func HandleXpRoleEditRole(ctx context.Context, dg bot.Session, i *interaction.Me func HandleXpRoleEditLevelStart(ctx context.Context, dg bot.Session, i *interaction.MessageComponent, params *XpRoleId) { id := params.ID cfg := GetGuild(ctx, i.GuildID) - _, xpRole := cfg.FindXpRole(id) + xpRole := cfg.FindXpRole(id) if xpRole == nil { err := interaction.Respond(i.Interaction, &interaction.Response{ Type: types.InteractionResponseChannelMessageWithSource, @@ -272,7 +273,7 @@ func HandleXpRoleEditLevel(ctx context.Context, dg bot.Session, i *interaction.M xp := exp.LevelXP(uint(level)) cfg := GetGuild(ctx, i.GuildID) - _, xpRole := cfg.FindXpRole(id) + xpRole := cfg.FindXpRole(id) if xpRole == nil { err = interaction.Respond(i.Interaction, &interaction.Response{ Type: types.InteractionResponseChannelMessageWithSource, @@ -287,7 +288,7 @@ func HandleXpRoleEditLevel(ctx context.Context, dg bot.Session, i *interaction.M return } xpRole.XP = xp - err = xpRole.Save(ctx) + err = xpRole.Save(ctx, common.GetDB(ctx)) if err != nil { bot.Logger(ctx).Error("saving config", "guild", i.GuildID, "id", id, "type", "edit") } @@ -297,7 +298,7 @@ func HandleXpRoleEditLevel(ctx context.Context, dg bot.Session, i *interaction.M func HandleXpRoleDel(ctx context.Context, dg bot.Session, i *interaction.MessageComponent, parameters *XpRoleId) { id := parameters.ID cfg := GetGuild(ctx, i.GuildID) - _, role := cfg.FindXpRole(id) + role := cfg.FindXpRole(id) if role == nil { err := interaction.Respond(i.Interaction, &interaction.Response{ Type: types.InteractionResponseChannelMessageWithSource, @@ -311,7 +312,7 @@ func HandleXpRoleDel(ctx context.Context, dg bot.Session, i *interaction.Message } return } - err := role.Delete(ctx) + err := role.Delete(ctx, common.GetDB(ctx)) if err != nil { bot.Logger(ctx).Error("deleting entry", "error", err, "guild", i.GuildID, "id", id, "type", "del") } @@ -344,11 +345,11 @@ func HandleXpRoleAdd(ctx context.Context, dg bot.Session, i *interaction.ModalSu } cfg := GetGuild(ctx, i.GuildID) - cfg.XpRoles = append(cfg.XpRoles, XpRole{ + cfg.XpRoles = append(cfg.XpRoles, &XpRole{ XP: xp, RoleID: roleId, }) - err = cfg.Save(ctx) + err = cfg.Save(ctx, common.GetDB(ctx)) if err != nil { bot.Logger(ctx).Error("saving config", "error", err, "role", roleId, "guild", i.GuildID) return |
