mirror of
https://github.com/keanuplayz/TravBot-v3.git
synced 2024-08-15 02:33:12 +00:00
Turned the help command into a paginated embed
This commit is contained in:
parent
72ff144cc0
commit
653cc6f8a6
5 changed files with 75 additions and 27 deletions
|
@ -1,4 +1,4 @@
|
|||
# ???
|
||||
# 3.2.1
|
||||
- `vaporwave`: Transforms input into full-width text
|
||||
- `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
|
||||
|
@ -7,8 +7,10 @@
|
|||
- `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
|
||||
- `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.
|
||||
- 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.
|
||||
|
|
|
@ -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.
|
||||
- `%prefix%` - The prefix of the current guild.
|
||||
- `%command%` - The command's execution path up to the current subcommand.
|
||||
|
||||
# Utility Functions
|
||||
|
||||
|
@ -72,11 +73,12 @@ Because versions are assigned to batches of changes rather than single changes (
|
|||
|
||||
`paginate()`
|
||||
```ts
|
||||
const pages = ['one', 'two', 'three'];
|
||||
const msg = await channel.send(pages[0]);
|
||||
const pages = ["one", "two", "three"];
|
||||
|
||||
paginate(msg, author.id, pages.length, (page) => {
|
||||
msg.edit(pages[page]);
|
||||
paginate(channel, author.id, pages.length, (page) => {
|
||||
return {
|
||||
content: pages[page]
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
|
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "travebot",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "travebot",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.1",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "travebot",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.1",
|
||||
"description": "TravBot Discord bot.",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -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 {MessageEmbed} from "discord.js";
|
||||
|
||||
const EMBED_COLOR = "#158a28";
|
||||
|
||||
export default new NamedCommand({
|
||||
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"],
|
||||
async run({message, channel, guild, author, member, client, args}) {
|
||||
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) {
|
||||
output += `\n\n===[ ${category} ]===`;
|
||||
for (const command of commandList) output += `\n- \`${command.name}\`: ${command.description}`;
|
||||
}
|
||||
|
||||
channel.send(output, {split: true});
|
||||
paginate(channel, author.id, categoryArray.length, (page, hasMultiplePages) => {
|
||||
const category = categoryArray[page];
|
||||
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}`;
|
||||
return new MessageEmbed()
|
||||
.setTitle(hasMultiplePages ? `${category} (Page ${page + 1} of ${categoryArray.length})` : category)
|
||||
.setDescription(output)
|
||||
.setColor(EMBED_COLOR);
|
||||
});
|
||||
},
|
||||
any: new Command({
|
||||
async run({message, channel, guild, author, member, client, args}) {
|
||||
|
@ -29,17 +44,17 @@ export default new NamedCommand({
|
|||
|
||||
for (const [tag, subcommand] of result.keyedSubcommandInfo) {
|
||||
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) {
|
||||
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 {
|
||||
append = `Usage: \`${header} ${command.usage}\``;
|
||||
append = `\`${header} ${command.usage}\``;
|
||||
}
|
||||
|
||||
let aliases = "N/A";
|
||||
|
@ -52,12 +67,41 @@ export default new NamedCommand({
|
|||
}
|
||||
|
||||
return channel.send(
|
||||
`Command: \`${header}\`\nAliases: ${aliases}\nCategory: \`${category}\`\nPermission Required: \`${getPermissionName(
|
||||
result.permission
|
||||
)}\` (${result.permission})\nChannel Type: ${getChannelTypeName(result.channelType)}\nNSFW Only: ${
|
||||
result.nsfw ? "Yes" : "No"
|
||||
}\nDescription: ${command.description}\n${append}`,
|
||||
{split: true}
|
||||
new MessageEmbed()
|
||||
.setTitle(header)
|
||||
.setDescription(command.description)
|
||||
.setColor(EMBED_COLOR)
|
||||
.addFields(
|
||||
{
|
||||
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
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue