Skip to content

Commit

Permalink
fix(cmds): option choices were incorrectly serializing to disk (fixes #…
Browse files Browse the repository at this point in the history
…83)

This was caused by it being deserialized as `JsonPrimitive`, and then this object being serialized back to disk.
  • Loading branch information
axieum committed Jul 28, 2023
1 parent e252ddb commit 2560393
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import me.shedaniel.autoconfig.serializer.ConfigSerializer;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.JsonPrimitive;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;

Expand Down Expand Up @@ -300,8 +301,16 @@ public void validatePostLoad()
messages.feedbackNode = parseNode(messages.feedback);
builtin.uptime.messageNode = parseNode(builtin.uptime.message);

// Parse command templates
Arrays.stream(custom).forEach(cmd -> cmd.commandNode = parseNode(cmd.command));
// Validate custom commands
Arrays.stream(custom).forEach(cmd -> {
// Parse command templates
cmd.commandNode = parseNode(cmd.command);
// Unwrap command option-choice primitives
Arrays.stream(cmd.options)
.flatMap(option -> Arrays.stream(option.choices))
.filter(choice -> choice.value instanceof JsonPrimitive)
.forEach(choice -> choice.value = ((JsonPrimitive) choice.value).getValue());
});

// Register all Minecord provided commands
MinecordCommandsImpl.initCommands(this);
Expand Down

0 comments on commit 2560393

Please sign in to comment.