Closed neolectron closed 1 year ago
I think one of the blocker is that we do not have a module-creator.
I tried several things, and in order to get all the keys inside the env
object in a module, I need to declare my modules as satisfies BotModule
which can be annoying for modules dev.
Then the solution was to have a function like getEnv()
that would be typesafe and return the requested environment variables. I couldn't do it simply.
Therefore I would consider putting this on blocked until we have the module-creator. I picture 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
}
},
}));
deprecated by #81
Problem
Modules aren't encapsulated, they should have a schema to define the shape of the environment they need.
Solution
Allow modules to export a zodSchema to validate env.