blob: a6c7479ff771e005a367b9a7f061600b882a2119 [file] [log] [blame]
pineafanad54d752022-04-18 19:01:43 +01001import { CommandInteraction, MessageActionRow, MessageButton, MessageSelectMenu } from "discord.js";
pineafan4edb7762022-06-26 19:21:04 +01002import { SlashCommandBuilder } from "@discordjs/builders";
pineafanad54d752022-04-18 19:01:43 +01003import { WrappedCheck } from "jshaiku";
pineafan4edb7762022-06-26 19:21:04 +01004import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafanad54d752022-04-18 19:01:43 +01005import generateKeyValueList, { toCapitals } from "../utils/generateKeyValueList.js";
6import getEmojiByName from "../utils/getEmojiByName.js";
pineafan4edb7762022-06-26 19:21:04 +01007import client from "../utils/client.js"
pineafanad54d752022-04-18 19:01:43 +01008
9const command = new SlashCommandBuilder()
10 .setName("categorise")
11 .setDescription("Categorises your servers channels")
12
pineafan4edb7762022-06-26 19:21:04 +010013const callback = async (interaction: CommandInteraction): Promise<any> => {
PineappleFanb3dd83c2022-06-17 10:53:48 +010014 const { renderChannel } = client.logger
pineafanad54d752022-04-18 19:01:43 +010015
16 let channels = interaction.guild.channels.cache.filter(c => c.type !== "GUILD_CATEGORY");
17 let categorised = {}
18
pineafan4edb7762022-06-26 19:21:04 +010019 await interaction.reply({embeds: [new EmojiEmbed()
pineafanad54d752022-04-18 19:01:43 +010020 .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
pineafan4edb7762022-06-26 19:21:04 +010044 await interaction.editReply({embeds: [new EmojiEmbed()
pineafanad54d752022-04-18 19:01:43 +010045 .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)
pineafanad54d752022-04-18 19:01:43 +010063 .setOptions(Object.keys(types).map(type => {return {label: toCapitals(type), value: type}}))
64 ])]});
65 }
66}
67
68const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
69 return true;
70}
71
72export { command };
73export { callback };
74export { check };