blob: c75d1bbfe1522e79c6c2de7770f103eee41a4d4f [file] [log] [blame]
pineafane23c4ec2022-07-27 21:56:27 +01001import { LoadingEmbed } from '../utils/defaultEmbeds.js';
pineafan73a7c4a2022-07-24 10:38:04 +01002import { CommandInteraction, GuildChannel, MessageActionRow, MessageButton, MessageSelectMenu } from "discord.js";
pineafane23c4ec2022-07-27 21:56:27 +01003import { SlashCommandBuilder } from "@discordjs/builders";
pineafanad54d752022-04-18 19:01:43 +01004import { WrappedCheck } from "jshaiku";
pineafan4edb7762022-06-26 19:21:04 +01005import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafan4edb7762022-06-26 19:21:04 +01006import client from "../utils/client.js"
pineafan73a7c4a2022-07-24 10:38:04 +01007import addPlural from "../utils/plurals.js";
8import getEmojiByName from "../utils/getEmojiByName.js";
pineafanad54d752022-04-18 19:01:43 +01009
pineafane23c4ec2022-07-27 21:56:27 +010010const command = new SlashCommandBuilder()
pineafanad54d752022-04-18 19:01:43 +010011 .setName("categorise")
12 .setDescription("Categorises your servers channels")
13
pineafan4edb7762022-06-26 19:21:04 +010014const callback = async (interaction: CommandInteraction): Promise<any> => {
pineafanad54d752022-04-18 19:01:43 +010015 let channels = interaction.guild.channels.cache.filter(c => c.type !== "GUILD_CATEGORY");
16 let categorised = {}
pineafane23c4ec2022-07-27 21:56:27 +010017 await interaction.reply({embeds: LoadingEmbed, ephemeral: true});
pineafan73a7c4a2022-07-24 10:38:04 +010018 let predicted = {}
19 let types = {
20 general: ["general", "muted", "main", "topic", "discuss"],
21 commands: ["bot", "command", "music"],
22 images: ["pic", "selfies", "image"],
23 nsfw: ["porn", "nsfw", "sex"],
24 links: ["links"],
25 advertising: ["ads", "advert", "server", "partner"],
26 staff: ["staff", "mod", "admin"],
27 spam: ["spam"],
28 other: ["random"]
29 }
pineafanad54d752022-04-18 19:01:43 +010030 for (let c of channels.values()) {
pineafanad54d752022-04-18 19:01:43 +010031 for (let type in types) {
32 for (let word of types[type]) {
33 if (c.name.toLowerCase().includes(word)) {
pineafan73a7c4a2022-07-24 10:38:04 +010034 predicted[c.id] = predicted[c.id] ?? []
35 predicted[c.id].push(type)
pineafanad54d752022-04-18 19:01:43 +010036 }
37 }
38 }
pineafanad54d752022-04-18 19:01:43 +010039 }
pineafan73a7c4a2022-07-24 10:38:04 +010040 let m;
41 for (let c of channels) {
42 // convert channel to a channel if its a string
43 let channel: any
pineafan73a7c4a2022-07-24 10:38:04 +010044 if (typeof c === "string") channel = interaction.guild.channels.cache.get(channel).id
pineafan02ba0232022-07-24 22:16:15 +010045 else channel = (c[0] as unknown as GuildChannel).id
pineafan73a7c4a2022-07-24 10:38:04 +010046 console.log(channel)
47 if (!predicted[channel]) predicted[channel] = []
48 m = await interaction.editReply({embeds: [new EmojiEmbed()
49 .setTitle("Categorise")
50 .setDescription(`Select all types that apply to <#${channel}>.\n\n` +
51 `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(", ")}`)
52 .setEmoji("CHANNEL.CATEGORY.CREATE")
53 .setStatus("Success")
54 ], components: [
55 new MessageActionRow().addComponents([new MessageSelectMenu()
56 .setCustomId("selected")
57 .setMaxValues(Object.keys(types).length)
58 .setMinValues(1)
59 .setPlaceholder("Select all types that apply to this channel")
60 .setOptions(Object.keys(types).map(type => ({label: type, value: type})))
61 ]),
62 new MessageActionRow().addComponents([
63 new MessageButton().setLabel("Accept Suggestion").setCustomId("accept").setStyle("SUCCESS").setDisabled(predicted[channel].length === 0)
64 .setEmoji(client.emojis.cache.get(getEmojiByName("ICONS.TICK", "id"))),
65 new MessageButton().setLabel("Use \"Other\"").setCustomId("reject").setStyle("SECONDARY")
66 .setEmoji(client.emojis.cache.get(getEmojiByName("ICONS.CROSS", "id")))
67 ])
68 ]})
69 let i;
70 try {
71 i = await m.awaitMessageComponent({ time: 300000 });
72 } catch (e) {
73 return await interaction.editReply({embeds: [new EmojiEmbed()
74 .setTitle("Categorise")
75 .setEmoji("CHANNEL.CATEGORY.DELETE")
76 .setStatus("Danger")
77 .setDescription(`Select all types that apply to <#${channel}>.\n\n` +
78 `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(", ")}`)
79 .setFooter({text: "Message timed out"})
80 ]})
81 }
82 i.deferUpdate()
83 let selected;
84 if (i.customId === "select") { selected = i.values; }
85 if (i.customId === "accept") { selected = predicted[channel]; }
86 if (i.customId === "reject") { selected = ["other"]; }
87 categorised[channel] = selected
88 }
89 console.log(categorised)
pineafanad54d752022-04-18 19:01:43 +010090}
91
92const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
93 return true;
94}
95
96export { command };
97export { callback };
98export { check };