Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Commit

Permalink
configurable menu time for RichDisplay (#57)
Browse files Browse the repository at this point in the history
* makes menu closing time configurable for developers

* fix helpMessage to show code blocks on mobile correctly (replacement for for #44)

* add jump + firstLast to typedefs

* fixes as requested

* Update index.d.ts
  • Loading branch information
pedall authored and bdistin committed Oct 26, 2017
1 parent b93cfb5 commit 95e4d4f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/commands/System/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = class extends Command {
const categories = Object.keys(help);
const helpMessage = [];
for (let cat = 0; cat < categories.length; cat++) {
helpMessage.push(`**${categories[cat]} Commands**: \`\`\`asciidoc`);
helpMessage.push(`**${categories[cat]} Commands**: \`\`\`asciidoc`, '');
const subCategories = Object.keys(help[categories[cat]]);
for (let subCat = 0; subCat < subCategories.length; subCat++) helpMessage.push(`= ${subCategories[subCat]} =`, `${help[categories[cat]][subCategories[subCat]].join('\n')}\n`);
helpMessage.push('```\n\u200b');
Expand Down
8 changes: 7 additions & 1 deletion src/lib/util/ReactionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class ReactionHandler extends ReactionCollector {
*/
this.prompt = this.options.prompt || 'Which page would you like to jump to?';

/**
* The time until the reaction collector closes automatically
* @type {number}
*/
this.time = typeof this.options.time === 'number' ? this.options.time : 30000;

/**
* Whether the menu is awaiting a response of a prompt, to block all other jump reactions
* @type {boolean}
Expand Down Expand Up @@ -150,7 +156,7 @@ class ReactionHandler extends ReactionCollector {
if (this.awaiting) return;
this.awaiting = true;
const mes = await this.message.channel.send(this.prompt);
const collected = await this.message.channel.awaitMessages(mess => mess.author === user, { max: 1, time: 30000 });
const collected = await this.message.channel.awaitMessages(mess => mess.author === user, { max: 1, time: this.time });
this.awaiting = false;
await mes.delete();
if (!collected.size) return;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/util/RichDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class RichDisplay {
* @memberof RichDisplay
* @property {Function} [filter] A filter function to add to the ReactionHandler
* @property {boolean} [stop = true] If a stop reaction should be included
* @property {boolean} [jump = true] If a jump reaction should be included
* @property {boolean} [firstLast = true] If a first and last reaction should be included
* @property {string} [prompt = 'Which page would you like to jump to?'] The prompt to be used when awaiting user input on a page to jump to
* @property {number} [startPage = 0] The page to start the RichDisplay on
* @property {number} [max] The maximum total amount of reactions to collect
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ declare module 'klasa' {
public methodMap: Map<string, emoji>;
public currentPage: number;
public prompt: string;
public time: number;
public awaiting: boolean;
public selection: Promise<number?>;
public reactionsDone: boolean;
Expand Down

0 comments on commit 95e4d4f

Please sign in to comment.