-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdocs.command.ts
More file actions
116 lines (104 loc) · 3.74 KB
/
docs.command.ts
File metadata and controls
116 lines (104 loc) · 3.74 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { Command } from "@crystaldevelopment/command-handler/dist";
import { ApplicationCommandOptionType } from "discord-api-types";
import {
ApplicationCommandOptionData,
CommandInteraction,
MessageActionRow,
MessageSelectMenu,
} from "discord.js";
import Bot from "../managers/Bot";
import StringSimilarity from "../util/StringSimilarity";
export default class extends Command {
public name = "docs";
public description = "Link NamelessMC documentation";
public options: ApplicationCommandOptionData[] = [
{
name: "parameter",
type: ApplicationCommandOptionType.String as number,
description:
"The parameter to query, leave blank for a list of all parameters",
autocomplete: true,
},
];
public onStart(): void {
null;
}
public onLoad(): void {
null;
}
public async run(interaction: CommandInteraction): Promise<any> {
const client = interaction.client as Bot;
const parameter = interaction.options
.getString("parameter")
?.toLowerCase();
const commandInfo = JSON.parse(
client.github.getFileFromRepo(`./commands/docs.json`)
);
// Return a list of all parameters if none are given
if (!parameter) {
const embed = client.embeds
.base()
.setTitle(commandInfo.title)
.setDescription(
"Available parameters: "
+ commandInfo.parameters
.map((c: string) => `\`${c}\``)
.join(", ")
);
interaction.reply({ embeds: [embed], ephemeral: true });
return;
}
try {
const command = JSON.parse(
client.github.getFileFromRepo(
`./commands/docs/${parameter}.json`
)
);
if (!command) return;
return interaction.reply({
embeds: [client.embeds.MakeResponse(command)],
});
} catch {
const matches = commandInfo.parameters.filter(
(c: string) =>
StringSimilarity(c, parameter) > 0.5
);
if (matches.length > 1) {
const row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId("docs-parameter")
.setPlaceholder("Select a parameter")
.addOptions(
matches.map((c: string) => {
return {
label: c,
description: `Select paremeter ${c}`,
value: c,
};
})
)
);
interaction.reply({
content: "That parameter doesn't exist. Did you mean:",
components: [row],
ephemeral: true,
});
} else if (matches.length == 1) {
const command = JSON.parse(
client.github.getFileFromRepo(
`./commands/docs/${matches[0]}.json`
)
);
if (!command) return;
return interaction.reply({
embeds: [client.embeds.MakeResponse(command)],
});
} else {
interaction.reply({
content: "That parameter doesn't exist",
ephemeral: true,
});
}
}
}
}