Archived
0
0
Fork 0

fix(help): btns causing crash if reach end of pages

This commit is contained in:
Daryl Ronningen 2021-06-30 18:43:34 -05:00
parent 7d870f06fb
commit 7cf734ec68
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
3 changed files with 14 additions and 7 deletions

View file

@ -15,6 +15,7 @@
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/
import Command from '@structures/command';
import { capitalize } from '@utils/utils';
import config from 'config';
import { Client, Message, MessageButton, MessageEmbed, MessageSelectMenu, MessageSelectOptionData } from 'discord.js';
import i18next from 'i18next';
@ -24,6 +25,7 @@ export default class extends Command {
super(client, file, {
shortDescription: i18next.t('commands:help.shortDescription'),
extendedDescription: i18next.t('commands:help.extendedDescription'),
usage: 'vm',
args: [
{
name: 'command',
@ -58,7 +60,7 @@ export default class extends Command {
commandGroups.forEach((val, index) => {
val.embed = new MessageEmbed();
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.setFooter(`Page ${index + 1}/${commandGroups.length}`);
val.embed.setTimestamp();
@ -87,7 +89,7 @@ export default class extends Command {
chooseHelpCategory.setPlaceholder(i18next.t('commands:help.categoryPlaceholder'));
for(const category of categories) {
dropDownOptions.push({ label: category, value: category });
dropDownOptions.push({ label: capitalize(category), value: category });
}
chooseHelpCategory.addOptions(dropDownOptions);
@ -109,7 +111,7 @@ export default class extends Command {
previousCategoryBtn.setDisabled(false);
}
if(currentPage !== 0) {
if(currentPage + 1 !== commandGroups.length) {
nextCategoryBtn.setDisabled(false);
previousCategoryBtn.setDisabled(true);
}
@ -127,7 +129,7 @@ export default class extends Command {
nextCategoryBtn.setDisabled(false);
}
if(currentPage !== 0) {
if(currentPage + 1 !== commandGroups.length) {
nextCategoryBtn.setDisabled(false);
previousCategoryBtn.setDisabled(true);
}
@ -145,7 +147,7 @@ export default class extends Command {
nextCategoryBtn.setDisabled(false);
}
if(currentPage !== 0) {
if(currentPage + 1 !== commandGroups.length) {
nextCategoryBtn.setDisabled(false);
previousCategoryBtn.setDisabled(true);
}
@ -178,12 +180,13 @@ export default class extends Command {
if(findCommand) {
const commandEmbed = new MessageEmbed();
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.setTimestamp();
commandEmbed.setDescription(i18next.t('commands:help.commandDescription', {
name: findCommand.options.name,
category: capitalize(findCommand.options.group!),
description: findCommand.options.extendedDescription ?? i18next.t('commands:generic.noExtendedDescription'),
usage: findCommand.options.usage ? `!${findCommand.options.name} ${findCommand.options.usage}` : i18next.t('commands:generic.noUsage'),
}));

View file

@ -15,7 +15,6 @@
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/
import Command from '@structures/command';
import type { Client, Message } from 'discord.js';
import i18next from 'i18next';
import { transpile } from 'typescript';
@ -26,6 +25,7 @@ export default class extends Command {
super(client, file, {
shortDescription: i18next.t('commands:vm.shortDescription'),
extendedDescription: i18next.t('commands:vm.extendedDescription'),
usage: 'js const test = \'test\'; return test;',
args: [
{
name: 'language',

View file

@ -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);
};