blob: 4a28841bd3f36551ee18dcf7d7c8dfc152e921e9 [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) => {
PineappleFanb3dd83c2022-06-17 10:53:48 +010013 const { renderChannel } = client.logger
pineafanad54d752022-04-18 19:01:43 +010014
15 let channels = interaction.guild.channels.cache.filter(c => c.type !== "GUILD_CATEGORY");
16 let categorised = {}
17
18 await interaction.reply({embeds: [new generateEmojiEmbed()
19 .setTitle("Loading...")
20 .setEmoji("NUCLEUS.LOADING")
21 .setStatus("Success")
22 ], ephemeral: true});
23 for (let c of channels.values()) {
24 let predicted = []
25 let types = {
26 general: ["general"],
27 commands: ["bot", "command", "music"],
28 images: ["pic", "selfies", "image"],
29 nsfw: ["porn", "nsfw", "sex"],
30 links: ["links"],
31 advertising: ["ads", "advert", "server", "partner"],
32 staff: ["staff", "mod", "admin"]
33 }
34
35 for (let type in types) {
36 for (let word of types[type]) {
37 if (c.name.toLowerCase().includes(word)) {
38 predicted.push(type)
39 }
40 }
41 }
42
43 await interaction.editReply({embeds: [new generateEmojiEmbed()
44 .setTitle("Categorise")
45 .setDescription(generateKeyValueList({
46 channel: renderChannel(c),
47 category: c.parent ? c.parent.name : "Uncategorised"
48 }) + "\n\n" + `Suggested tags: ${predicted.join(", ")}`)
49 .setEmoji("CHANNEL.TEXT.CREATE")
50 .setStatus("Success")
51 ], components: [ new MessageActionRow().addComponents([
52 new MessageButton()
53 .setLabel("Use suggested")
54 .setStyle("PRIMARY")
55 .setCustomId("accept")
56 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
57 ]), new MessageActionRow().addComponents([new MessageSelectMenu()
58 .setPlaceholder("Select a category")
59 .setCustomId("category")
60 .setMinValues(0)
61 .setMaxValues(1)
pineafanad54d752022-04-18 19:01:43 +010062 .setOptions(Object.keys(types).map(type => {return {label: toCapitals(type), value: type}}))
63 ])]});
64 }
65}
66
67const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
68 return true;
69}
70
71export { command };
72export { callback };
73export { check };