-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add better help command and command module
- Loading branch information
Showing
17 changed files
with
255 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { EmbedBuilder, type EmbedField, codeBlock } from "discord.js" | ||
import { string } from "zod" | ||
import Command from "../../../../structures/Command.js" | ||
import type { CommandType } from "../../../../typings/Commands.js" | ||
|
||
// A sub commands of help | ||
export default new Command({ | ||
data: { | ||
name: "list", | ||
description: "Get a list of all available commands.", | ||
}, | ||
async run(command) { | ||
const commands = Array.from(command.client.commands) | ||
|
||
if (commands.length < 1) return await command.reply("There are no commands available") | ||
|
||
type SimplifiedHelpCommand = { name: string; body: CommandType } | ||
const helpMap = new Map<string, SimplifiedHelpCommand[]>() | ||
for (const [name, body] of commands) { | ||
const commandHelp = { name, body } | ||
|
||
// biome-ignore lint/style/noNonNullAssertion: Categories are set during command modules register | ||
const category = body.category! | ||
|
||
const existingCommandHelp = helpMap.get(category) | ||
if (Array.isArray(existingCommandHelp)) { | ||
helpMap.set(category, [...existingCommandHelp, commandHelp]) | ||
} else { | ||
helpMap.set(category, [commandHelp]) | ||
} | ||
} | ||
|
||
const helpArr = Array.from(helpMap).sort(([categoryA], [categoryB]) => { | ||
return categoryA.localeCompare(categoryB) | ||
}) | ||
|
||
let content = "## List of all available commands" | ||
for (const [category, commands] of helpArr) { | ||
content += `\n### ${category}` | ||
for (const cmd of commands.toSorted((a, b) => a.name.localeCompare(b.name))) { | ||
content += `\n\`/${cmd.name.replace("-", " ")}\`: ${cmd.body.data.description}` | ||
} | ||
} | ||
|
||
await command.reply(content) | ||
}, | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import chalk from "chalk" | ||
|
||
export default class Print { | ||
static title(...text: unknown[]) { | ||
console.log(chalk.bold(chalk.green(...text))) | ||
} | ||
|
||
static gray(...text: unknown[]) { | ||
console.log(chalk.bold(chalk.gray(...text))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { srcDir } from "../dirname.js" | ||
import Print from "../functions/log/Color.js" | ||
import type ExtendedClient from "../structures/Client.js" | ||
import type { ButtonType } from "../typings/Buttons.js" | ||
|
||
export default async (client: ExtendedClient) => { | ||
const path = `${srcDir}/interaction/buttons` | ||
|
||
const files = await client.getFiles(path) | ||
Print.title("[Module]", "loading Buttons") | ||
|
||
const buttons: ButtonType[] = await Promise.all(files.map((file) => client.importFile(file))) | ||
const files = await client.getFiles(path) | ||
|
||
for (const button of buttons) client.buttons.set(button.id, button) | ||
for await (const file of files) { | ||
const button = (await client.importFile(file)) as ButtonType | ||
Print.gray("[Button]", `ID:${button.id}`) | ||
client.buttons.set(button.id, button) | ||
} | ||
} |
Oops, something went wrong.