Turned the help command into a paginated embed

This commit is contained in:
WatDuhHekBro 2021-04-09 23:33:22 -05:00
parent 72ff144cc0
commit 653cc6f8a6
5 changed files with 75 additions and 27 deletions

View file

@ -1,4 +1,4 @@
# ??? # 3.2.1
- `vaporwave`: Transforms input into full-width text - `vaporwave`: Transforms input into full-width text
- `eco post`: A play on `eco get` - `eco post`: A play on `eco get`
- `admin set prefix <prefix> (<@bot>)`: Allows you to target a bot when setting a prefix if two bots have conflicting prefixes - `admin set prefix <prefix> (<@bot>)`: Allows you to target a bot when setting a prefix if two bots have conflicting prefixes
@ -7,8 +7,10 @@
- `thonk`: A result can now be discarded if the person who called the command reacts with ❌ - `thonk`: A result can now be discarded if the person who called the command reacts with ❌
- `scanemotes forcereset`: Removes the cooldown on `scanemotes`, only accessible by bot support and up - `scanemotes forcereset`: Removes the cooldown on `scanemotes`, only accessible by bot support and up
- `urban`: Bug fixes - `urban`: Bug fixes
- Changed `help` to display a paginated embed
- Various changes to core
# 3.2.0 - Internal refactor, more subcommand types, and more command type guards (2021-??-??) # 3.2.0 - Internal refactor, more subcommand types, and more command type guards (2021-04-09)
- The custom logger changed: `$.log` no longer exists, it's just `console.log`. Now you don't have to do `import $ from "../core/lib"` at the top of every file that uses the custom logger. - The custom logger changed: `$.log` no longer exists, it's just `console.log`. Now you don't have to do `import $ from "../core/lib"` at the top of every file that uses the custom logger.
- Utility functions are no longer attached to the command menu. Stuff like `$.paginate()` and `$(5).pluralise()` instead need to be imported and used as regular functions. - Utility functions are no longer attached to the command menu. Stuff like `$.paginate()` and `$(5).pluralise()` instead need to be imported and used as regular functions.
- The `paginate` function was reworked to reduce the amount of repetition you had to do. - The `paginate` function was reworked to reduce the amount of repetition you had to do.

View file

@ -65,6 +65,7 @@ Because versions are assigned to batches of changes rather than single changes (
- `%author%` - A user mention of the person who called the command. - `%author%` - A user mention of the person who called the command.
- `%prefix%` - The prefix of the current guild. - `%prefix%` - The prefix of the current guild.
- `%command%` - The command's execution path up to the current subcommand.
# Utility Functions # Utility Functions
@ -72,11 +73,12 @@ Because versions are assigned to batches of changes rather than single changes (
`paginate()` `paginate()`
```ts ```ts
const pages = ['one', 'two', 'three']; const pages = ["one", "two", "three"];
const msg = await channel.send(pages[0]);
paginate(msg, author.id, pages.length, (page) => { paginate(channel, author.id, pages.length, (page) => {
msg.edit(pages[page]); return {
content: pages[page]
};
}); });
``` ```

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "travebot", "name": "travebot",
"version": "3.2.0", "version": "3.2.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "travebot", "name": "travebot",
"version": "3.2.0", "version": "3.2.1",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View file

@ -1,6 +1,6 @@
{ {
"name": "travebot", "name": "travebot",
"version": "3.2.0", "version": "3.2.1",
"description": "TravBot Discord bot.", "description": "TravBot Discord bot.",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {

View file

@ -1,5 +1,16 @@
import {Command, NamedCommand, CHANNEL_TYPE, getPermissionName, getCommandList, getCommandInfo} from "../../core"; import {
Command,
NamedCommand,
CHANNEL_TYPE,
getPermissionName,
getCommandList,
getCommandInfo,
paginate
} from "../../core";
import {requireAllCasesHandledFor} from "../../lib"; import {requireAllCasesHandledFor} from "../../lib";
import {MessageEmbed} from "discord.js";
const EMBED_COLOR = "#158a28";
export default new NamedCommand({ export default new NamedCommand({
description: "Lists all commands. If a command is specified, their arguments are listed as well.", description: "Lists all commands. If a command is specified, their arguments are listed as well.",
@ -7,14 +18,18 @@ export default new NamedCommand({
aliases: ["h"], aliases: ["h"],
async run({message, channel, guild, author, member, client, args}) { async run({message, channel, guild, author, member, client, args}) {
const commands = await getCommandList(); const commands = await getCommandList();
let output = `Legend: \`<type>\`, \`[list/of/stuff]\`, \`(optional)\`, \`(<optional type>)\`, \`([optional/list/...])\``; const categoryArray = commands.keyArray();
for (const [category, commandList] of commands) { paginate(channel, author.id, categoryArray.length, (page, hasMultiplePages) => {
output += `\n\n===[ ${category} ]===`; const category = categoryArray[page];
for (const command of commandList) output += `\n- \`${command.name}\`: ${command.description}`; const commandList = commands.get(category)!;
} let output = `Legend: \`<type>\`, \`[list/of/stuff]\`, \`(optional)\`, \`(<optional type>)\`, \`([optional/list/...])\`\n`;
for (const command of commandList) output += `\n \`${command.name}\`: ${command.description}`;
channel.send(output, {split: true}); return new MessageEmbed()
.setTitle(hasMultiplePages ? `${category} (Page ${page + 1} of ${categoryArray.length})` : category)
.setDescription(output)
.setColor(EMBED_COLOR);
});
}, },
any: new Command({ any: new Command({
async run({message, channel, guild, author, member, client, args}) { async run({message, channel, guild, author, member, client, args}) {
@ -29,17 +44,17 @@ export default new NamedCommand({
for (const [tag, subcommand] of result.keyedSubcommandInfo) { for (const [tag, subcommand] of result.keyedSubcommandInfo) {
const customUsage = subcommand.usage ? ` ${subcommand.usage}` : ""; const customUsage = subcommand.usage ? ` ${subcommand.usage}` : "";
list.push(`- \`${header} ${tag}${customUsage}\` - ${subcommand.description}`); list.push(` \`${header} ${tag}${customUsage}\` - ${subcommand.description}`);
} }
for (const [type, subcommand] of result.subcommandInfo) { for (const [type, subcommand] of result.subcommandInfo) {
const customUsage = subcommand.usage ? ` ${subcommand.usage}` : ""; const customUsage = subcommand.usage ? ` ${subcommand.usage}` : "";
list.push(`- \`${header} ${type}${customUsage}\` - ${subcommand.description}`); list.push(` \`${header} ${type}${customUsage}\` - ${subcommand.description}`);
} }
append = "Usages:" + (list.length > 0 ? `\n${list.join("\n")}` : " None."); append = list.length > 0 ? list.join("\n") : "None";
} else { } else {
append = `Usage: \`${header} ${command.usage}\``; append = `\`${header} ${command.usage}\``;
} }
let aliases = "N/A"; let aliases = "N/A";
@ -52,12 +67,41 @@ export default new NamedCommand({
} }
return channel.send( return channel.send(
`Command: \`${header}\`\nAliases: ${aliases}\nCategory: \`${category}\`\nPermission Required: \`${getPermissionName( new MessageEmbed()
result.permission .setTitle(header)
)}\` (${result.permission})\nChannel Type: ${getChannelTypeName(result.channelType)}\nNSFW Only: ${ .setDescription(command.description)
result.nsfw ? "Yes" : "No" .setColor(EMBED_COLOR)
}\nDescription: ${command.description}\n${append}`, .addFields(
{split: true} {
name: "Aliases",
value: aliases,
inline: true
},
{
name: "Category",
value: category,
inline: true
},
{
name: "Permission Required",
value: `\`${getPermissionName(result.permission)}\` (Level ${result.permission})`,
inline: true
},
{
name: "Channel Type",
value: getChannelTypeName(result.channelType),
inline: true
},
{
name: "NSFW Only?",
value: result.nsfw ? "Yes" : "No",
inline: true
},
{
name: "Usages",
value: append
}
)
); );
} }
}) })