Skip to content

Commit

Permalink
feat: add SessionManager#resolve()
Browse files Browse the repository at this point in the history
  • Loading branch information
Amgelo563 committed Jul 9, 2024
1 parent b7f8108 commit fae4114
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/features/session/SessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export interface SessionManager extends BotAware, BotLifecycleObserver {
meta?: SessionExecutionMeta,
): Awaitable<this>;

/** Resolves an {@link Session} given a {@link SessionUpdateInteraction}. */
resolve(
interaction: SessionUpdateInteraction,
): Awaitable<Session<unknown> | null>;

/** Returns the event subscriber for {@link SessionUpdateInteraction}. */
getUpdateSubscriber(): EventSubscriber<
ClientEvents,
Expand Down
11 changes: 11 additions & 0 deletions packages/framework/src/features/session/DefaultSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,17 @@ export class DefaultSessionManager implements SessionManager {
return this;
}

public resolve(
interaction: SessionUpdateInteraction,
): Promise<Session<unknown> | null> {
const { customId } = interaction;
const sessionCustomId = this.codec.deserializeToObjectId(customId);

if (!sessionCustomId) return Promise.resolve(null);

return this.repository.get(sessionCustomId);
}

public async setUpdateSubscriber(
subscriber: EventSubscriber<ClientEvents, Events.InteractionCreate>,
): Promise<this> {
Expand Down

0 comments on commit fae4114

Please sign in to comment.