Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ReactionHandler

Klasa's ReactionHandler, for handling RichDisplay and RichMenu reaction input

Hierarchy

  • ReactionHandler

Index

Constructors

constructor

Properties

Private #awaiting

#awaiting: boolean = false

If we are awaiting a jump response

Private #currentPage

#currentPage: number

The current page the display is on

since

0.4.0

Private #ended

#ended: boolean = false

If this ReactionHandler has ended

since

0.6.0

Private #resolve

#resolve: ((value?: number | PromiseLike<number | null> | null | undefined) => void) | null = null

Causes this.selection to resolve

since

0.4.0

Private Readonly display

display: RichDisplay

The RichDisplay/RichMenu this Handler is for

since

0.4.0

Private Readonly jumpTimeout

jumpTimeout: number

The amount of time before the jump menu should close

since

0.4.0

Private Readonly message

message: Message

The message of the RichDisplay/RichMenu

since

0.6.0

Private Readonly methodMap

methodMap: Map<string, ReactionMethods>

An emoji to method map, to map custom emojis to static method names

since

0.4.0

Private Readonly prompt

prompt: string

The prompt to use when jumping pages

since

0.4.0

Readonly selection

selection: Promise<number | null>

The selection of a RichMenu (useless in a RichDisplay scenario)

since

0.4.0

Static Private methods

methods: Map<ReactionMethods, (this: ReactionHandler, user: User) => Promise<boolean>> = new Map().set(ReactionMethods.First, function (this: ReactionHandler): Promise<boolean> {this.#currentPage = 0;return this.update();}).set(ReactionMethods.Back, function (this: ReactionHandler): Promise<boolean> {if (this.#currentPage <= 0) return Promise.resolve(false);this.#currentPage--;return this.update();}).set(ReactionMethods.Forward, function (this: ReactionHandler): Promise<boolean> {if (this.#currentPage >= this.display.pages.length - 1) return Promise.resolve(false);this.#currentPage++;return this.update();}).set(ReactionMethods.Last, function (this: ReactionHandler): Promise<boolean> {this.#currentPage = this.display.pages.length - 1;return this.update();}).set(ReactionMethods.Jump, async function (this: ReactionHandler, user: User): Promise<boolean> {if (this.#awaiting) return Promise.resolve(false);this.#awaiting = true;const [message] = await this.message.channel.send(mb => mb.setContent(this.prompt));const collected = await this.message.channel.awaitMessages({ filter: ([mess]) => mess.author === user, limit: 1, idle: this.jumpTimeout });this.#awaiting = false;await message.delete();const response = collected.firstValue;if (!response) return Promise.resolve(false);const newPage = parseInt(response.content);await response.delete();if (newPage && newPage > 0 && newPage <= this.display.pages.length) {this.#currentPage = newPage - 1;return this.update();}return Promise.resolve(false);}).set(ReactionMethods.Info, async function (this: ReactionHandler): Promise<boolean> {if (this.message.deleted) return true;// eslint-disable-next-line @typescript-eslint/no-non-null-assertionawait this.message.edit(mb => mb.setEmbed(this.display.infoPage!));return false;}).set(ReactionMethods.Stop, function (this: ReactionHandler): Promise<boolean> {return Promise.resolve(this.stop());}).set(ReactionMethods.One, function (this: ReactionHandler): Promise<boolean> {return this.choose(this.#currentPage * 10);}).set(ReactionMethods.Two, function (this: ReactionHandler): Promise<boolean> {return this.choose(1 + (this.#currentPage * 10));}).set(ReactionMethods.Three, function (this: ReactionHandler): Promise<boolean> {return this.choose(2 + (this.#currentPage * 10));}).set(ReactionMethods.Four, function (this: ReactionHandler): Promise<boolean> {return this.choose(3 + (this.#currentPage * 10));}).set(ReactionMethods.Five, function (this: ReactionHandler): Promise<boolean> {return this.choose(4 + (this.#currentPage * 10));}).set(ReactionMethods.Six, function (this: ReactionHandler): Promise<boolean> {return this.choose(5 + (this.#currentPage * 10));}).set(ReactionMethods.Seven, function (this: ReactionHandler): Promise<boolean> {return this.choose(6 + (this.#currentPage * 10));}).set(ReactionMethods.Eight, function (this: ReactionHandler): Promise<boolean> {return this.choose(7 + (this.#currentPage * 10));}).set(ReactionMethods.Nine, function (this: ReactionHandler): Promise<boolean> {return this.choose(8 + (this.#currentPage * 10));}).set(ReactionMethods.Ten, function (this: ReactionHandler): Promise<boolean> {return this.choose(9 + (this.#currentPage * 10));})

The reaction methods

since

0.6.0

Methods

Private choose

  • choose(value: number): Promise<boolean>

Private run

  • run(emojis: string[], options: ReactionIteratorOptions): Promise<void>
  • Runs this ReactionHandler

    Parameters

    • emojis: string[]

      The emojis to react

    • options: ReactionIteratorOptions

      The options for the Iterator

    Returns Promise<void>

Private setup

  • setup(emojis: string[]): Promise<boolean>

stop

  • stop(): boolean

Private update

  • update(): Promise<boolean>

Generated using TypeDoc