Amgelo
Amgelo
Explore posts from servers
SIASapphire - Imagine a framework
Created by Amgelo on 11/19/2024 in #sapphire-support
Serializing string-store result inside another schema
I'm trying to re-work customId serialization in my framework, and my plan is to use string-store for this. One of the features in my framework is that you can make customIds that refer to commands, kind of like this:
class MyCommand extends Command {
public async execute(i: ChatInputInteraction, meta: Metadata) {
const bot = meta.getBot();
const customId = bot.getCommandManager().getCustomIdSerializer().serialize(this);
// reply with button or something that uses the customId
}

public executeComponent(i: ComponentInteraction) {
i.reply('Hello!')
}
}
class MyCommand extends Command {
public async execute(i: ChatInputInteraction, meta: Metadata) {
const bot = meta.getBot();
const customId = bot.getCommandManager().getCustomIdSerializer().serialize(this);
// reply with button or something that uses the customId
}

public executeComponent(i: ComponentInteraction) {
i.reply('Hello!')
}
}
The serializer and the router in the command manager then work together to properly route interactions to the #executeComponent() method. My problem comes from how to implement string-store's serialization for this. My main idea was to do something like this (on #execute()):
// data is passed as "extra" data, that the serializer doesn't care about what it actually is, it only knows it's a string
const data = store.serialize(/** data */);
const customId = bot.getCommandManager().getCustomIdSerializer().serialize(this, data);
// data is passed as "extra" data, that the serializer doesn't care about what it actually is, it only knows it's a string
const data = store.serialize(/** data */);
const customId = bot.getCommandManager().getCustomIdSerializer().serialize(this, data);
#executeComponent() would then accept an extra, optional parameter, which would be the user-provided data as a string, resolved from the customId. The way this would work is by making the customIdSerializer have a schema with a store like this:
new Schema(Id.Something).string('extraData').../** other data needed to actually resolve the command */;
new Schema(Id.Something).string('extraData').../** other data needed to actually resolve the command */;
The advantage of this is that the user isn't forced to use string-store, they can just pass anything and they'll receive it back. But then if they do use string-store, the user would be serializing the string, and then the framework would be serializing it again, and I wonder if that could cause issues (from my poor testing it doesn't look like it but I'm pretty much nobody compared to the actual maintainers, maybe there's edge cases). Maybe I'm overthinking it and there's a better way?
42 replies
SIASapphire - Imagine a framework
Created by Amgelo on 11/7/2024 in #sapphire-support
SchemaStore narrowed to never
No description
29 replies
DIdiscord.js - Imagine ❄
Created by Amgelo on 5/8/2024 in #djs-questions
Cloning a SlashCommandBuilder
Is there a way to automatically clone a SlashCommandBuilder? Its constructor is empty and there's no clone or .from() method
23 replies
DIdiscord.js - Imagine ❄
Created by Amgelo on 4/15/2024 in #djs-questions
Mapping command data to an ApplicationCommand
Hi, I'm trying to make a way to recognize if there's an ApplicationCommand that matches (exactly) the data from a SlashCommandBuilder. I checked this https://old.discordjs.dev/#/docs/discord.js/14.14.1/class/ApplicationCommand?scrollTo=equals but it seems to take the entire ApplicationCommand data (like application id), and I couldn't find another related method that works only for the data of the command itself. Ideally I want something built-in inside djs, without needing to code this check myself. Thanks!
38 replies