Open neolectron opened 1 year ago
See #57 .
I think we will need sooner that I thought the module-creator.
Many benefits, one of them is you don't have to import the type BotModule
anymore, and it will be far easier to pass something to a feature (especially if the thing passed to the feature depends on the module definition).
For now, I imagine something like :
export const myModule = createModule((ctx) => ({
env: {
MY_ENV_VAR: z.string().optionnal()
},
storage: {
channelList: z.string().array()
},
slashCommands: {/*...*/},
eventHandlers: {
messageCreate: async () => {
// Here I would be able to use ctx.env and ctx.storage
console.log(ctx.storage.channelList) // typesafe + can be validated
}
},
}));
Problem
I've notices that even after the new module abstraction we still have to wire some of the stuff outside of the module.
to name a few :
src/config.ts
src/core/cache.ts
Solution
To fix the leaky abstraction, we should allow users to provide this configuration within the scope of their module.
I'm keen into taking a shot at this next time I work on the bot.