blob: 2852a2b9fbbc6f606cb406dc24d9d80823aebb10 [file] [log] [blame]
pineafanad54d752022-04-18 19:01:43 +01001import { CommandInteraction, MessageActionRow, MessageButton, MessageSelectMenu } from "discord.js";
2import { SelectMenuComponent, SelectMenuOption, SlashCommandBuilder } from "@discordjs/builders";
3import { WrappedCheck } from "jshaiku";
4import generateEmojiEmbed from "../utils/generateEmojiEmbed.js";
5import generateKeyValueList, { toCapitals } from "../utils/generateKeyValueList.js";
6import getEmojiByName from "../utils/getEmojiByName.js";
7
8const command = new SlashCommandBuilder()
9 .setName("categorise")
10 .setDescription("Categorises your servers channels")
11
12const callback = async (interaction: CommandInteraction) => {
13 // @ts-ignore
14 const { renderChannel } = interaction.client.logger
15
16 let channels = interaction.guild.channels.cache.filter(c => c.type !== "GUILD_CATEGORY");
17 let categorised = {}
18
19 await interaction.reply({embeds: [new generateEmojiEmbed()
20 .setTitle("Loading...")
21 .setEmoji("NUCLEUS.LOADING")
22 .setStatus("Success")
23 ], ephemeral: true});
24 for (let c of channels.values()) {
25 let predicted = []
26 let types = {
27 general: ["general"],
28 commands: ["bot", "command", "music"],
29 images: ["pic", "selfies", "image"],
30 nsfw: ["porn", "nsfw", "sex"],
31 links: ["links"],
32 advertising: ["ads", "advert", "server", "partner"],
33 staff: ["staff", "mod", "admin"]
34 }
35
36 for (let type in types) {
37 for (let word of types[type]) {
38 if (c.name.toLowerCase().includes(word)) {
39 predicted.push(type)
40 }
41 }
42 }
43
44 await interaction.editReply({embeds: [new generateEmojiEmbed()
45 .setTitle("Categorise")
46 .setDescription(generateKeyValueList({
47 channel: renderChannel(c),
48 category: c.parent ? c.parent.name : "Uncategorised"
49 }) + "\n\n" + `Suggested tags: ${predicted.join(", ")}`)
50 .setEmoji("CHANNEL.TEXT.CREATE")
51 .setStatus("Success")
52 ], components: [ new MessageActionRow().addComponents([
53 new MessageButton()
54 .setLabel("Use suggested")
55 .setStyle("PRIMARY")
56 .setCustomId("accept")
57 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
58 ]), new MessageActionRow().addComponents([new MessageSelectMenu()
59 .setPlaceholder("Select a category")
60 .setCustomId("category")
61 .setMinValues(0)
62 .setMaxValues(1)
63 // .setMaxValues(Object.keys(types).length)
64 .setOptions(Object.keys(types).map(type => {return {label: toCapitals(type), value: type}}))
65 ])]});
66 }
67}
68
69const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
70 return true;
71}
72
73export { command };
74export { callback };
75export { check };