⌛ Session Promise Repository
The SessionPromiseRepository
is the object responsible for creating session end promises. It's stored by a
SessionManager
, and you can get it via SessionManager#getPromiseRepository()
.
You can use this object to create a promise that will be resolved with its end data when a session ends or expires.
⌛ Obtaining a promise
const repository = bot.getSessionManager().getPromiseRepository();
const promise = repository.getPromise(session);
// Or:
const promise = session.getEndPromise();
const endData = await promise;
const sessionResult = endData.result;
👷 Creation
You can create a custom session promise repository by either:
- Extending
DefaultSessionPromiseRepository
from@framework
(recommended). - Implementing the
SessionPromiseRepository
interface from@core
.
- Extending DefaultSessionPromiseRepository
- Implementing SessionExecutor
import { DefaultSessionPromiseRepository } from '@nyx-discord/framework';
class MySessionPromiseRepository extends DefaultSessionPromiseRepository {
// ...
}
const myRepository = new MySessionPromiseRepository();
const myBot = Bot.create((bot) => ({
sessions: DefaultSessionManager.create(bot, { promiseRepository: myRepository }),
}));
import { SessionPromiseRepository } from '@nyx-discord/core';
class MySessionPromiseRepository implements SessionPromiseRepository {
// ...
}
const myRepository = new MySessionPromiseRepository();
const myBot = Bot.create((bot) => ({
sessions: DefaultSessionManager.create(bot, { promiseRepository: myRepository }),
}));