forked from neplextech/commandkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.ts
More file actions
77 lines (69 loc) · 2.25 KB
/
help.ts
File metadata and controls
77 lines (69 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { CommandData, ChatInputCommand } from 'commandkit';
import { redEmbedColor } from '@/feature-flags/red-embed-color';
import { toMessageRoute, toSlashRoute } from '@/utils/hierarchical-demo';
import { Colors } from 'discord.js';
export const command: CommandData = {
name: 'help',
description: 'This is a help command.',
};
function $botVersion(): string {
'use macro';
const { join } = require('node:path');
const path = join(process.cwd(), 'package.json');
return require(path).version;
}
export const chatInput: ChatInputCommand = async (ctx) => {
const showRedColor = await redEmbedColor();
const { interaction } = ctx;
await interaction.deferReply();
const botVersion = $botVersion();
let i = 1;
const commands = ctx.commandkit.commandHandler
.getCommandsArray()
.map((c) => {
const cmdName = c.data.command.name;
const cmd = c.discordId
? `</${cmdName}:${c.discordId}>`
: `**\`/${cmdName}\`**`;
return `${i++}. ${cmd} - ${c.command.category ?? 'N/A'}`;
})
.join('\n');
const hierarchicalRoutes = ctx.commandkit.commandHandler
.getRuntimeCommandsArray()
.map((command) => {
return (
(command.data.command as Record<string, any>).__routeKey ??
command.data.command.name
);
})
.filter((route) => route.includes('.'))
.sort()
.map((route) => `${toSlashRoute(route)} | ${toMessageRoute(route)}`)
.join('\n');
return interaction.editReply({
embeds: [
{
title: 'Help',
description: commands,
fields: hierarchicalRoutes
? [
{
name: 'Hierarchical Routes',
value: hierarchicalRoutes,
},
{
name: 'Hierarchical Middleware',
value:
'Global middleware always runs first. Hierarchical leaves then use only the current directory `+middleware` and any same-directory `+<command>.middleware`.',
},
]
: undefined,
footer: {
text: `Bot Version: ${botVersion} | Shard ID ${interaction.guild?.shardId ?? 'N/A'}`,
},
color: showRedColor ? Colors.Red : Colors.Blurple,
timestamp: new Date().toISOString(),
},
],
});
};