blob: cbd9924d6f1d6a5d9e6ef99f58e96aa5dc85d7c5 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../utils/defaults.js";
TheCodedProf267563a2023-01-21 17:00:57 -05002import { CommandInteraction, GuildChannel, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, StringSelectMenuBuilder, APIMessageComponentEmoji } from "discord.js";
pineafane23c4ec2022-07-27 21:56:27 +01003import { SlashCommandBuilder } from "@discordjs/builders";
pineafan4edb7762022-06-26 19:21:04 +01004import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafan63fc5e22022-08-04 22:04:10 +01005import client from "../utils/client.js";
pineafan73a7c4a2022-07-24 10:38:04 +01006import addPlural from "../utils/plurals.js";
7import getEmojiByName from "../utils/getEmojiByName.js";
pineafanad54d752022-04-18 19:01:43 +01008
TheCodedProf267563a2023-01-21 17:00:57 -05009const command = new SlashCommandBuilder().setName("categorize").setDescription("Categorizes your servers channels");
pineafanad54d752022-04-18 19:01:43 +010010
Skyler Greyc634e2b2022-08-06 17:50:48 +010011const callback = async (interaction: CommandInteraction): Promise<unknown> => {
TheCodedProf267563a2023-01-21 17:00:57 -050012 const channels = interaction.guild!.channels.cache.filter((c) => c.type !== ChannelType.GuildCategory);
13 const categorized = {};
Skyler Grey75ea9172022-08-06 10:22:23 +010014 await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
pineafan63fc5e22022-08-04 22:04:10 +010015 const predicted = {};
16 const types = {
TheCodedProf267563a2023-01-21 17:00:57 -050017 important: ["rule", "announcement", "alert", "info"],
18 general: ["general", "main", "topic", "discuss"],
pineafan73a7c4a2022-07-24 10:38:04 +010019 commands: ["bot", "command", "music"],
TheCodedProf267563a2023-01-21 17:00:57 -050020 images: ["pic", "selfies", "image", "gallery", "meme", "media"],
21 nsfw: ["porn", "nsfw", "sex", "lewd", "fetish"],
22 links: ["link"],
23 advertising: ["ads", "advert", "partner", "bump"],
24 staff: ["staff", "mod", "admin", "helper", "train"],
25 spam: ["spam", "count"],
26 logs: ["log"],
27 other: ["random", "starboard"],
pineafan63fc5e22022-08-04 22:04:10 +010028 };
29 for (const c of channels.values()) {
30 for (const type in types) {
31 for (const word of types[type]) {
pineafanad54d752022-04-18 19:01:43 +010032 if (c.name.toLowerCase().includes(word)) {
pineafan63fc5e22022-08-04 22:04:10 +010033 predicted[c.id] = predicted[c.id] ?? [];
34 predicted[c.id].push(type);
pineafanad54d752022-04-18 19:01:43 +010035 }
36 }
37 }
pineafanad54d752022-04-18 19:01:43 +010038 }
pineafan73a7c4a2022-07-24 10:38:04 +010039 let m;
pineafan63fc5e22022-08-04 22:04:10 +010040 for (const c of channels) {
pineafan73a7c4a2022-07-24 10:38:04 +010041 // convert channel to a channel if its a string
pineafanbd02b4a2022-08-05 22:01:38 +010042 let channel: string | GuildChannel;
TheCodedProf267563a2023-01-21 17:00:57 -050043 if (typeof c === "string") channel = interaction.guild!.channels.cache.get(c as string)!.id;
pineafan63fc5e22022-08-04 22:04:10 +010044 else channel = (c[0] as unknown as GuildChannel).id;
45 console.log(channel);
46 if (!predicted[channel]) predicted[channel] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +010047 m = await interaction.editReply({
48 embeds: [
49 new EmojiEmbed()
TheCodedProf267563a2023-01-21 17:00:57 -050050 .setTitle("Categorize")
Skyler Grey75ea9172022-08-06 10:22:23 +010051 .setDescription(
52 `Select all types that apply to <#${channel}>.\n\n` +
Skyler Grey11236ba2022-08-08 21:13:33 +010053 `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(", ")}`
Skyler Grey75ea9172022-08-06 10:22:23 +010054 )
55 .setEmoji("CHANNEL.CATEGORY.CREATE")
56 .setStatus("Success")
57 ],
58 components: [
TheCodedProf267563a2023-01-21 17:00:57 -050059 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
60 new StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010061 .setCustomId("selected")
62 .setMaxValues(Object.keys(types).length)
63 .setMinValues(1)
Skyler Grey11236ba2022-08-08 21:13:33 +010064 .setPlaceholder("Select all types that apply to this channel")
Skyler Grey75ea9172022-08-06 10:22:23 +010065 .setOptions(
66 Object.keys(types).map((type) => ({
67 label: type,
68 value: type
69 }))
70 )
71 ]),
TheCodedProf267563a2023-01-21 17:00:57 -050072 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -040073 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010074 .setLabel("Accept Suggestion")
75 .setCustomId("accept")
TheCodedProf21c08592022-09-13 14:14:43 -040076 .setStyle(ButtonStyle.Success)
Skyler Grey75ea9172022-08-06 10:22:23 +010077 .setDisabled(predicted[channel].length === 0)
TheCodedProf267563a2023-01-21 17:00:57 -050078 .setEmoji(client.emojis.cache.get(getEmojiByName("ICONS.TICK", "id")) as APIMessageComponentEmoji),
TheCodedProf21c08592022-09-13 14:14:43 -040079 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010080 .setLabel('Use "Other"')
81 .setCustomId("reject")
TheCodedProf21c08592022-09-13 14:14:43 -040082 .setStyle(ButtonStyle.Secondary)
TheCodedProf267563a2023-01-21 17:00:57 -050083 .setEmoji(client.emojis.cache.get(getEmojiByName("ICONS.CROSS", "id")) as APIMessageComponentEmoji)
Skyler Grey75ea9172022-08-06 10:22:23 +010084 ])
85 ]
86 });
pineafan73a7c4a2022-07-24 10:38:04 +010087 let i;
88 try {
PineaFan0d06edc2023-01-17 22:10:31 +000089 i = await m.awaitMessageComponent({
90 time: 300000,
TheCodedProf267563a2023-01-21 17:00:57 -050091 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id}
PineaFan0d06edc2023-01-17 22:10:31 +000092 });
pineafan73a7c4a2022-07-24 10:38:04 +010093 } catch (e) {
Skyler Grey75ea9172022-08-06 10:22:23 +010094 return await interaction.editReply({
95 embeds: [
96 new EmojiEmbed()
TheCodedProf267563a2023-01-21 17:00:57 -050097 .setTitle("Categorize")
Skyler Grey75ea9172022-08-06 10:22:23 +010098 .setEmoji("CHANNEL.CATEGORY.DELETE")
99 .setStatus("Danger")
100 .setDescription(
101 `Select all types that apply to <#${channel}>.\n\n` +
Skyler Grey11236ba2022-08-08 21:13:33 +0100102 `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(
103 ", "
104 )}`
Skyler Grey75ea9172022-08-06 10:22:23 +0100105 )
106 .setFooter({ text: "Message timed out" })
107 ]
108 });
pineafan73a7c4a2022-07-24 10:38:04 +0100109 }
TheCodedProf267563a2023-01-21 17:00:57 -0500110 await i.deferUpdate();
pineafan73a7c4a2022-07-24 10:38:04 +0100111 let selected;
Skyler Grey75ea9172022-08-06 10:22:23 +0100112 if (i.customId === "select") {
113 selected = i.values;
114 }
115 if (i.customId === "accept") {
116 selected = predicted[channel];
117 }
118 if (i.customId === "reject") {
119 selected = ["other"];
120 }
TheCodedProf267563a2023-01-21 17:00:57 -0500121 categorized[channel] = selected;
pineafan73a7c4a2022-07-24 10:38:04 +0100122 }
TheCodedProf267563a2023-01-21 17:00:57 -0500123 console.log(categorized);
pineafan63fc5e22022-08-04 22:04:10 +0100124};
pineafanad54d752022-04-18 19:01:43 +0100125
PineaFan0d06edc2023-01-17 22:10:31 +0000126const check = () => {
pineafanad54d752022-04-18 19:01:43 +0100127 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100128};
pineafanad54d752022-04-18 19:01:43 +0100129
130export { command };
131export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100132export { check };