How can I partition custom id schemas using `@sapphire/string-store`

I created 2 different schema stores, where each store keeps track of schemas for a particular feature of the bot. I then use the parse method of interaction handlers to determine whether a given interaction should be handled by it, as such:
public override async parse(interaction: ButtonInteraction) {
const deserializedCustomId = MinesGameQuickPlayConfigurationMessage.customIdStore.deserialize(interaction.customId);
if (deserializedCustomId.id === QuickPlayConfigurationCustomIdSchema.SetBetAmount) return this.some(deserializedCustomId.data);
return this.none();
}
public override async parse(interaction: ButtonInteraction) {
const deserializedCustomId = MinesGameQuickPlayConfigurationMessage.customIdStore.deserialize(interaction.customId);
if (deserializedCustomId.id === QuickPlayConfigurationCustomIdSchema.SetBetAmount) return this.some(deserializedCustomId.data);
return this.none();
}
And in another handler, deserializing using a different schema store:
public override async parse(interaction: ButtonInteraction) {
const deserializedCustomId = MinesGameMessage.customIdStore.deserialize(interaction.customId);
if (deserializedCustomId.id === MinesGameCustomIdSchema.QuickPlayConfiguration) return this.some(deserializedCustomId.data);
return this.none();
}
public override async parse(interaction: ButtonInteraction) {
const deserializedCustomId = MinesGameMessage.customIdStore.deserialize(interaction.customId);
if (deserializedCustomId.id === MinesGameCustomIdSchema.QuickPlayConfiguration) return this.some(deserializedCustomId.data);
return this.none();
}
Since both enums hold the same integer value, both of these handlers are executed, which is not what I am trying to achieve. I am wondering if I need to use a single schema store for each type of interaction (button/select menu/etc) or if there is any way I could categorize/partition them
1 Reply
Teixeira
TeixeiraOP16h ago
Another idea would be to actually give values to enum members rather than letting them default to integers but then I would have to make sure they are unique between stores (could just add a unique prefix to all of each store's enum members but it's a bit ugly 🙁 ) Adding an id property to the schemas themselves that identified it would be an option too, but not ideal either

Did you find this page helpful?