fix(help): btns causing crash if reach end of pages
This commit is contained in:
parent
7d870f06fb
commit
7cf734ec68
3 changed files with 14 additions and 7 deletions
|
@ -15,6 +15,7 @@
|
||||||
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import Command from '@structures/command';
|
import Command from '@structures/command';
|
||||||
|
import { capitalize } from '@utils/utils';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { Client, Message, MessageButton, MessageEmbed, MessageSelectMenu, MessageSelectOptionData } from 'discord.js';
|
import { Client, Message, MessageButton, MessageEmbed, MessageSelectMenu, MessageSelectOptionData } from 'discord.js';
|
||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
|
@ -24,6 +25,7 @@ export default class extends Command {
|
||||||
super(client, file, {
|
super(client, file, {
|
||||||
shortDescription: i18next.t('commands:help.shortDescription'),
|
shortDescription: i18next.t('commands:help.shortDescription'),
|
||||||
extendedDescription: i18next.t('commands:help.extendedDescription'),
|
extendedDescription: i18next.t('commands:help.extendedDescription'),
|
||||||
|
usage: 'vm',
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
name: 'command',
|
name: 'command',
|
||||||
|
@ -58,7 +60,7 @@ export default class extends Command {
|
||||||
commandGroups.forEach((val, index) => {
|
commandGroups.forEach((val, index) => {
|
||||||
val.embed = new MessageEmbed();
|
val.embed = new MessageEmbed();
|
||||||
val.embed.setAuthor(i18next.t('commands:help.embedName'));
|
val.embed.setAuthor(i18next.t('commands:help.embedName'));
|
||||||
val.embed.setTitle(val.name.toUpperCase());
|
val.embed.setTitle(capitalize(val.name));
|
||||||
val.embed.setColor(message.member?.roles.highest.color ?? 0xFFFFFF);
|
val.embed.setColor(message.member?.roles.highest.color ?? 0xFFFFFF);
|
||||||
val.embed.setFooter(`Page ${index + 1}/${commandGroups.length}`);
|
val.embed.setFooter(`Page ${index + 1}/${commandGroups.length}`);
|
||||||
val.embed.setTimestamp();
|
val.embed.setTimestamp();
|
||||||
|
@ -87,7 +89,7 @@ export default class extends Command {
|
||||||
chooseHelpCategory.setPlaceholder(i18next.t('commands:help.categoryPlaceholder'));
|
chooseHelpCategory.setPlaceholder(i18next.t('commands:help.categoryPlaceholder'));
|
||||||
|
|
||||||
for(const category of categories) {
|
for(const category of categories) {
|
||||||
dropDownOptions.push({ label: category, value: category });
|
dropDownOptions.push({ label: capitalize(category), value: category });
|
||||||
}
|
}
|
||||||
|
|
||||||
chooseHelpCategory.addOptions(dropDownOptions);
|
chooseHelpCategory.addOptions(dropDownOptions);
|
||||||
|
@ -109,7 +111,7 @@ export default class extends Command {
|
||||||
previousCategoryBtn.setDisabled(false);
|
previousCategoryBtn.setDisabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentPage !== 0) {
|
if(currentPage + 1 !== commandGroups.length) {
|
||||||
nextCategoryBtn.setDisabled(false);
|
nextCategoryBtn.setDisabled(false);
|
||||||
previousCategoryBtn.setDisabled(true);
|
previousCategoryBtn.setDisabled(true);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +129,7 @@ export default class extends Command {
|
||||||
nextCategoryBtn.setDisabled(false);
|
nextCategoryBtn.setDisabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentPage !== 0) {
|
if(currentPage + 1 !== commandGroups.length) {
|
||||||
nextCategoryBtn.setDisabled(false);
|
nextCategoryBtn.setDisabled(false);
|
||||||
previousCategoryBtn.setDisabled(true);
|
previousCategoryBtn.setDisabled(true);
|
||||||
}
|
}
|
||||||
|
@ -145,7 +147,7 @@ export default class extends Command {
|
||||||
nextCategoryBtn.setDisabled(false);
|
nextCategoryBtn.setDisabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentPage !== 0) {
|
if(currentPage + 1 !== commandGroups.length) {
|
||||||
nextCategoryBtn.setDisabled(false);
|
nextCategoryBtn.setDisabled(false);
|
||||||
previousCategoryBtn.setDisabled(true);
|
previousCategoryBtn.setDisabled(true);
|
||||||
}
|
}
|
||||||
|
@ -178,12 +180,13 @@ export default class extends Command {
|
||||||
if(findCommand) {
|
if(findCommand) {
|
||||||
const commandEmbed = new MessageEmbed();
|
const commandEmbed = new MessageEmbed();
|
||||||
commandEmbed.setAuthor(i18next.t('commands:help.embedName'));
|
commandEmbed.setAuthor(i18next.t('commands:help.embedName'));
|
||||||
commandEmbed.setTitle(findCommand.options.name!.toUpperCase());
|
commandEmbed.setTitle(capitalize(findCommand.options.name!));
|
||||||
commandEmbed.setColor(message.member?.roles.highest.color ?? 0xFFFFFF);
|
commandEmbed.setColor(message.member?.roles.highest.color ?? 0xFFFFFF);
|
||||||
commandEmbed.setTimestamp();
|
commandEmbed.setTimestamp();
|
||||||
|
|
||||||
commandEmbed.setDescription(i18next.t('commands:help.commandDescription', {
|
commandEmbed.setDescription(i18next.t('commands:help.commandDescription', {
|
||||||
name: findCommand.options.name,
|
name: findCommand.options.name,
|
||||||
|
category: capitalize(findCommand.options.group!),
|
||||||
description: findCommand.options.extendedDescription ?? i18next.t('commands:generic.noExtendedDescription'),
|
description: findCommand.options.extendedDescription ?? i18next.t('commands:generic.noExtendedDescription'),
|
||||||
usage: findCommand.options.usage ? `!${findCommand.options.name} ${findCommand.options.usage}` : i18next.t('commands:generic.noUsage'),
|
usage: findCommand.options.usage ? `!${findCommand.options.name} ${findCommand.options.usage}` : i18next.t('commands:generic.noUsage'),
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import Command from '@structures/command';
|
import Command from '@structures/command';
|
||||||
|
|
||||||
import type { Client, Message } from 'discord.js';
|
import type { Client, Message } from 'discord.js';
|
||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
import { transpile } from 'typescript';
|
import { transpile } from 'typescript';
|
||||||
|
@ -26,6 +25,7 @@ export default class extends Command {
|
||||||
super(client, file, {
|
super(client, file, {
|
||||||
shortDescription: i18next.t('commands:vm.shortDescription'),
|
shortDescription: i18next.t('commands:vm.shortDescription'),
|
||||||
extendedDescription: i18next.t('commands:vm.extendedDescription'),
|
extendedDescription: i18next.t('commands:vm.extendedDescription'),
|
||||||
|
usage: 'js const test = \'test\'; return test;',
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
name: 'language',
|
name: 'language',
|
||||||
|
|
|
@ -53,3 +53,7 @@ export const walkDir = async (dir: string): Promise<string[]> => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const capitalize = (string: string): string => {
|
||||||
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||||
|
};
|
||||||
|
|
Reference in a new issue