Skip to content

Commit

Permalink
feat!: rename Session#start() to Session#onStart() and Session#update…
Browse files Browse the repository at this point in the history
…() to Session#onUpdate()
  • Loading branch information
Amgelo563 committed Jan 27, 2024
1 parent bec907f commit 0eb3645
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
13 changes: 10 additions & 3 deletions packages/core/src/features/session/session/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ export interface Session<Result>
Identifiable<string>,
Metadatable {
/**
* Starts the session.
* Starts the session. Alias of `SessionManager#start(this)`.
*
* @throws {IllegalStateError} If the session has already started.
*/
start(meta: SessionExecutionMeta): Awaitable<void>;
start(): Awaitable<void>;

/**
* Notifies the session about its start.
*
* @throws {IllegalStateError} If the session has already started.
*/
onStart(meta: SessionExecutionMeta): Awaitable<void>;

/**
* Updates the session's state with an interaction.
Expand All @@ -61,7 +68,7 @@ export interface Session<Result>
* @returns {boolean} Whether the session's TTL should be reset after this
* update.
*/
update(
onUpdate(
interaction: SessionUpdateInteraction,
meta: SessionExecutionMeta,
): Awaitable<boolean>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class DefaultSessionExecutor implements SessionExecutor {
}

try {
await session.start(meta);
await session.onStart(meta);

return true;
} catch (error) {
Expand Down Expand Up @@ -176,7 +176,7 @@ export class DefaultSessionExecutor implements SessionExecutor {
}

try {
return await session.update(interaction, meta);
return await session.onUpdate(interaction, meta);
} catch (error) {
await this.updateErrorHandler.handle(
error as object,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2023 Amgelo563
* Copyright (c) 2024 Amgelo563
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -62,15 +62,15 @@ export abstract class AbstractPaginationSession<Result>
this.currentPage = 0;
}

public override async update(
public override async onUpdate(
interaction: SessionUpdateInteraction,
meta: SessionExecutionMeta,
): Promise<boolean> {
const newPage = this.extractPageFromInteraction(interaction);

/** Not a page switch interaction, handle as normal. */
if (newPage === null) {
return super.update(interaction, meta);
return super.onUpdate(interaction, meta);
}

/** Switch page interaction. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ export abstract class AbstractSession<Result = void>
if (ttl !== undefined) this.ttl = ttl;
}

public async update(
public async start(): Promise<void> {
await this.bot.sessions.start(this);
}

public async onUpdate(
interaction: SessionUpdateInteraction,
meta: SessionExecutionMeta,
): Promise<boolean> {
Expand All @@ -107,7 +111,7 @@ export abstract class AbstractSession<Result = void>
return this.handleSelectMenu(interaction, meta);
}

public abstract start(meta: SessionExecutionMeta): Awaitable<void>;
public abstract onStart(meta: SessionExecutionMeta): Awaitable<void>;

public abstract onEnd(
reason: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export abstract class AbstractStagePaginationSession<Result>
{
protected abstract readonly stages: SessionStageArray;

public start(meta: SessionExecutionMeta): Awaitable<void> {
public onStart(meta: SessionExecutionMeta): Awaitable<void> {
const stage = this.stages[0];

return stage.onStart(this.startInteraction, meta);
}

public override async update(
public override async onUpdate(
interaction: SessionUpdateInteraction,
meta: SessionExecutionMeta,
): Promise<boolean> {
Expand Down

0 comments on commit 0eb3645

Please sign in to comment.