️💼 Session Manager
The SessionManager is the object that holds together the nyx session system.
It consists of:
SessionCustomIdCodecfor encoding and decoding custom session ids.SessionUpdateSubscriberfor listening to session updates.SessionRepositoryfor storing sessions.SessionExecutorfor executing sessions.SessionPromiseRepositoryfor storing session end promises.EventBusfor emitting session related events.
As well as methods to interact with them.
👷 Creation
You can create a custom session manager by either:
- Extending
DefaultSessionManagerfrom@nyx-discord/framework(recommended). - Implementing
SessionManagerfrom@nyx-discord/core.
Then you can pass it to your bot:
class MySessionManager extends DefaultSessionManager {
public myCustomPublicMethod() {}
}
const myBot = Bot.create((bot: NyxBot) => ({
// ...
sessions: new MySessionManager(/** ... */),
}));
mybot.getSessionManager().myCustomPublicMethod() // works!
The Bot class is able to infer the type of your custom manager via generics, so accessing any custom public method or
property will work without errors.