aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/dev/superUser.ts6
-rw-r--r--src/commands/info/help.ts142
-rw-r--r--src/commands/moderation/ban.ts2
-rw-r--r--src/commands/utilities/steal.ts4
4 files changed, 111 insertions, 43 deletions
diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts
index 57e2b86..d62ac8e 100644
--- a/src/commands/dev/superUser.ts
+++ b/src/commands/dev/superUser.ts
@@ -15,12 +15,12 @@ export default class SuperUserCommand extends BushCommand {
ownerOnly: true,
helpArgs: [
{
- id: 'action',
+ name: 'action',
description: 'Whether to add or remove a user from the superuser list.',
- readableType: 'add|remove'
+ type: "'add'|'remove'"
},
{
- id: 'user',
+ name: 'user',
description: 'The user to add/remove from the superuser list.',
type: 'user',
match: 'restContent'
diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts
index 7a30e64..ea1e965 100644
--- a/src/commands/info/help.ts
+++ b/src/commands/info/help.ts
@@ -11,6 +11,7 @@ import {
} from 'discord.js';
import Fuse from 'fuse.js';
import packageDotJSON from '../../../package.json' assert { type: 'json' };
+import { stripIndent } from '../../lib/common/tags.js';
assert(Fuse);
assert(packageDotJSON);
@@ -52,51 +53,71 @@ export default class HelpCommand extends BushCommand {
});
}
- public override async exec(
- message: BushMessage | BushSlashMessage,
- args: { command: ArgType<'commandAlias'> | string; showHidden?: boolean }
- ) {
- const prefix = util.prefix(message);
+ public override async exec(message: BushMessage | BushSlashMessage, args: HelpArgs) {
const row = this.addLinks(message);
-
- const isOwner = client.isOwner(message.author);
- const isSuperUser = client.isSuperUser(message.author);
const command = args.command
? typeof args.command === 'string'
? client.commandHandler.findCommand(args.command) ?? null
: args.command
: null;
- if (!isOwner) args.showHidden = false;
+
+ if (!message.author.isOwner()) args.showHidden = false;
+
if (!command || command.pseudo) {
- const embed = new EmbedBuilder().setColor(util.colors.default).setTimestamp();
- embed.setFooter({ text: `For more information about a command use ${prefix}help <command>` });
- for (const [, category] of this.handler.categories) {
- const categoryFilter = category.filter((command) => {
- if (command.pseudo) return false;
- if (command.hidden && !args.showHidden) return false;
- if (command.channel == 'guild' && !message.guild && !args.showHidden) return false;
- if (command.ownerOnly && !isOwner) return false;
- if (command.superUserOnly && !isSuperUser) return false;
- if (command.restrictedGuilds?.includes(message.guild?.id ?? '') === false && !args.showHidden) return false;
- if (command.aliases.length === 0) return false;
-
- return true;
- });
- const categoryNice = category.id
- .replace(/(\b\w)/gi, (lc) => lc.toUpperCase())
- .replace(/'(S)/g, (letter) => letter.toLowerCase());
- const categoryCommands = categoryFilter.filter((cmd) => cmd.aliases.length > 0).map((cmd) => `\`${cmd.aliases[0]}\``);
- if (categoryCommands.length > 0) {
- embed.addFields([{ name: `${categoryNice}`, value: `${categoryCommands.join(' ')}` }]);
- }
- }
- return await message.util.reply({ embeds: [embed], components: row.components.length ? [row] : undefined });
+ return this.helpAll(message, args, row);
+ } else {
+ return this.helpIndividual(message, row, command);
}
+ }
+ private helpAll(message: BushMessage | BushSlashMessage, args: HelpArgs, row: ActionRowBuilder<ButtonBuilder>) {
+ const prefix = util.prefix(message);
const embed = new EmbedBuilder()
.setColor(util.colors.default)
- .setTitle(`${command.id} Command`)
- .setDescription(`${command.description ?? '*This command does not have a description.*'}`);
+ .setTimestamp()
+ .setFooter({ text: `For more information about a command use ${prefix}help <command>` });
+ for (const [, category] of this.handler.categories) {
+ const categoryFilter = category.filter((command) => {
+ if (command.pseudo) return false;
+ if (command.hidden && !args.showHidden) return false;
+ if (command.channel == 'guild' && !message.guild && !args.showHidden) return false;
+ if (command.ownerOnly && !message.author.isOwner()) return false;
+ if (command.superUserOnly && !message.author.isSuperUser()) return false;
+ if (command.restrictedGuilds?.includes(message.guild?.id ?? '') === false && !args.showHidden) return false;
+ if (command.aliases.length === 0) return false;
+
+ return true;
+ });
+ const categoryNice = category.id
+ .replace(/(\b\w)/gi, (lc) => lc.toUpperCase())
+ .replace(/'(S)/g, (letter) => letter.toLowerCase());
+ const categoryCommands = categoryFilter.filter((cmd) => cmd.aliases.length > 0).map((cmd) => `\`${cmd.aliases[0]}\``);
+ if (categoryCommands.length > 0) {
+ embed.addFields([{ name: `${categoryNice}`, value: `${categoryCommands.join(' ')}` }]);
+ }
+ }
+ return message.util.reply({ embeds: [embed], components: row.components.length ? [row] : undefined });
+ }
+
+ private helpIndividual(message: BushMessage | BushSlashMessage, row: ActionRowBuilder<ButtonBuilder>, command: BushCommand) {
+ const embed = new EmbedBuilder().setColor(util.colors.default).setTitle(`${command.id} Command`);
+
+ let description = `${command.description ?? '*This command does not have a description.*'}`;
+ if (command.note) description += `\n\n${command.note}`;
+ embed.setDescription(description);
+
+ this.addCommandUsage(embed, command);
+ this.addCommandExamples(embed, command);
+ this.addCommandAliases(embed, command);
+ this.addCommandArguments(embed, command, message.author.isOwner(), message.author.isSuperUser());
+ this.addCommandRestrictions(embed, command);
+ // todo: permissions
+
+ const params = { embeds: [embed], components: row.components.length ? [row] : undefined };
+ return message.util.reply(params);
+ }
+
+ private addCommandUsage(embed: EmbedBuilder, command: BushCommand) {
if (command.usage?.length) {
embed.addFields([
{
@@ -105,6 +126,9 @@ export default class HelpCommand extends BushCommand {
}
]);
}
+ }
+
+ private addCommandExamples(embed: EmbedBuilder, command: BushCommand) {
if (command.examples?.length) {
embed.addFields([
{
@@ -113,7 +137,50 @@ export default class HelpCommand extends BushCommand {
}
]);
}
- if (command.aliases?.length > 1) embed.addFields([{ name: '» Aliases', value: `\`${command.aliases.join('` `')}\`` }]);
+ }
+
+ private addCommandAliases(embed: EmbedBuilder, command: BushCommand) {
+ if (command.aliases?.length > 1)
+ embed.addFields([
+ {
+ name: '» Aliases',
+ value: `\`${command.aliases.join('` `')}\``
+ }
+ ]);
+ }
+
+ private addCommandArguments(embed: EmbedBuilder, command: BushCommand, isOwner = false, isSuperUser = false) {
+ const format = (id: string, req: boolean) => `${req ? '<' : '['}${id}${req ? '>' : ']'}`;
+ const args = (command.argsInfo ?? []).filter((arg) => {
+ if (arg.ownerOnly && !isOwner) return false;
+ if (arg.superUserOnly && !isSuperUser) return false;
+ return true;
+ });
+ if (args.length) {
+ embed.addFields([
+ {
+ name: '» Arguments',
+ value: args
+ .map((a) => {
+ let ret = stripIndent`
+ \`${format(a.name, !!a.optional)}\`
+ ⠀‣ **Desc**: ${a.description}
+ ⠀‣ **Type**: ${typeof a.type !== 'function' ? a.type : '[no readable type]'}`;
+
+ if (a.flag?.length) ret += `\n⠀‣ **Flags**: ${a.flag.map((f) => `"${f}"`).join(', ')}`;
+ ret += `\n⠀‣ **Kind**: ${a.only ?? 'text & slash'}`;
+ if (a.only !== 'slash') ret += `\n⠀‣ **Match**: ${a.match}`;
+ if (a.only !== 'text') ret += `\n⠀‣ **Autocomplete**: ${a.autocomplete}`;
+
+ return ret;
+ })
+ .join('\n')
+ }
+ ]);
+ }
+ }
+
+ private addCommandRestrictions(embed: EmbedBuilder, command: BushCommand) {
if (
command.ownerOnly ||
command.superUserOnly ||
@@ -138,9 +205,6 @@ export default class HelpCommand extends BushCommand {
);
if (restrictions.length) embed.addFields([{ name: '» Restrictions', value: restrictions.join('\n') }]);
}
-
- const params = { embeds: [embed], components: row.components.length ? [row] : undefined };
- return await message.util.reply(params);
}
private addLinks(message: BushMessage | BushSlashMessage) {
@@ -181,3 +245,5 @@ export default class HelpCommand extends BushCommand {
void interaction.respond(res.length ? res : startingCommands);
}
}
+
+type HelpArgs = { command: ArgType<'commandAlias'> | string; showHidden?: boolean };
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts
index 14bbba6..77951c3 100644
--- a/src/commands/moderation/ban.ts
+++ b/src/commands/moderation/ban.ts
@@ -24,6 +24,7 @@ export default class BanCommand extends BushCommand {
id: 'user',
description: 'The user that will be banned.',
type: util.arg.union('user', 'snowflake'),
+ readableType: 'user|snowflake',
prompt: 'What user would you like to ban?',
retry: '{error} Choose a valid user to ban.',
slashType: ApplicationCommandOptionType.User
@@ -46,6 +47,7 @@ export default class BanCommand extends BushCommand {
prompt: "How many days of the user's messages would you like to delete?",
retry: '{error} Choose between 0 and 7 days to delete messages from the user for.',
type: util.arg.range('integer', 0, 7, true),
+ readableType: 'integer [0, 7]',
optional: true,
slashType: ApplicationCommandOptionType.Integer,
choices: [...Array(8).keys()].map((v) => ({ name: v.toString(), value: v }))
diff --git a/src/commands/utilities/steal.ts b/src/commands/utilities/steal.ts
index 765fb24..e4f08f1 100644
--- a/src/commands/utilities/steal.ts
+++ b/src/commands/utilities/steal.ts
@@ -31,8 +31,8 @@ export default class StealCommand extends BushCommand {
{ name: 'name', description: lang.nameStart, type: ApplicationCommandOptionType.String, required: false }
],
helpArgs: [
- { id: 'emoji', description: lang.emojiDescription, readableType: 'emoji|emojiId|url', optional: false },
- { id: 'name', description: lang.nameDescription, readableType: 'string', optional: true }
+ { name: 'emoji', description: lang.emojiDescription, type: 'emoji|emojiId|url', optional: false },
+ { name: 'name', description: lang.nameDescription, type: 'string', optional: true }
],
slash: true,
channel: 'guild',