blob: 763669c10236e8121b30a030ea05346d50ac17c0 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../utils/defaults.js";
Skyler Greyda16adf2023-03-05 10:22:12 +00002import {
3 CommandInteraction,
4 GuildChannel,
5 ActionRowBuilder,
6 ButtonBuilder,
7 ButtonStyle,
8 ChannelType,
9 StringSelectMenuBuilder,
10 APIMessageComponentEmoji
11} from "discord.js";
TheCodedProff86ba092023-01-27 17:10:07 -050012import { SlashCommandBuilder } from "discord.js";
pineafan4edb7762022-06-26 19:21:04 +010013import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafan63fc5e22022-08-04 22:04:10 +010014import client from "../utils/client.js";
pineafan73a7c4a2022-07-24 10:38:04 +010015import addPlural from "../utils/plurals.js";
16import getEmojiByName from "../utils/getEmojiByName.js";
pineafanad54d752022-04-18 19:01:43 +010017
TheCodedProf267563a2023-01-21 17:00:57 -050018const command = new SlashCommandBuilder().setName("categorize").setDescription("Categorizes your servers channels");
pineafanad54d752022-04-18 19:01:43 +010019
Skyler Greyc634e2b2022-08-06 17:50:48 +010020const callback = async (interaction: CommandInteraction): Promise<unknown> => {
TheCodedProf267563a2023-01-21 17:00:57 -050021 const channels = interaction.guild!.channels.cache.filter((c) => c.type !== ChannelType.GuildCategory);
22 const categorized = {};
Skyler Grey75ea9172022-08-06 10:22:23 +010023 await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
pineafan63fc5e22022-08-04 22:04:10 +010024 const predicted = {};
25 const types = {
TheCodedProf267563a2023-01-21 17:00:57 -050026 important: ["rule", "announcement", "alert", "info"],
27 general: ["general", "main", "topic", "discuss"],
pineafan73a7c4a2022-07-24 10:38:04 +010028 commands: ["bot", "command", "music"],
TheCodedProf267563a2023-01-21 17:00:57 -050029 images: ["pic", "selfies", "image", "gallery", "meme", "media"],
30 nsfw: ["porn", "nsfw", "sex", "lewd", "fetish"],
31 links: ["link"],
32 advertising: ["ads", "advert", "partner", "bump"],
33 staff: ["staff", "mod", "admin", "helper", "train"],
34 spam: ["spam", "count"],
35 logs: ["log"],
Skyler Greyda16adf2023-03-05 10:22:12 +000036 other: ["random", "starboard"]
pineafan63fc5e22022-08-04 22:04:10 +010037 };
38 for (const c of channels.values()) {
39 for (const type in types) {
40 for (const word of types[type]) {
pineafanad54d752022-04-18 19:01:43 +010041 if (c.name.toLowerCase().includes(word)) {
pineafan63fc5e22022-08-04 22:04:10 +010042 predicted[c.id] = predicted[c.id] ?? [];
43 predicted[c.id].push(type);
pineafanad54d752022-04-18 19:01:43 +010044 }
45 }
46 }
pineafanad54d752022-04-18 19:01:43 +010047 }
pineafan73a7c4a2022-07-24 10:38:04 +010048 let m;
pineafan63fc5e22022-08-04 22:04:10 +010049 for (const c of channels) {
pineafan73a7c4a2022-07-24 10:38:04 +010050 // convert channel to a channel if its a string
pineafanbd02b4a2022-08-05 22:01:38 +010051 let channel: string | GuildChannel;
TheCodedProf267563a2023-01-21 17:00:57 -050052 if (typeof c === "string") channel = interaction.guild!.channels.cache.get(c as string)!.id;
pineafan63fc5e22022-08-04 22:04:10 +010053 else channel = (c[0] as unknown as GuildChannel).id;
54 console.log(channel);
55 if (!predicted[channel]) predicted[channel] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +010056 m = await interaction.editReply({
57 embeds: [
58 new EmojiEmbed()
TheCodedProf267563a2023-01-21 17:00:57 -050059 .setTitle("Categorize")
Skyler Grey75ea9172022-08-06 10:22:23 +010060 .setDescription(
61 `Select all types that apply to <#${channel}>.\n\n` +
Skyler Grey11236ba2022-08-08 21:13:33 +010062 `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(", ")}`
Skyler Grey75ea9172022-08-06 10:22:23 +010063 )
64 .setEmoji("CHANNEL.CATEGORY.CREATE")
65 .setStatus("Success")
66 ],
67 components: [
TheCodedProf267563a2023-01-21 17:00:57 -050068 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
69 new StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010070 .setCustomId("selected")
71 .setMaxValues(Object.keys(types).length)
72 .setMinValues(1)
Skyler Grey11236ba2022-08-08 21:13:33 +010073 .setPlaceholder("Select all types that apply to this channel")
Skyler Grey75ea9172022-08-06 10:22:23 +010074 .setOptions(
75 Object.keys(types).map((type) => ({
76 label: type,
77 value: type
78 }))
79 )
80 ]),
TheCodedProf267563a2023-01-21 17:00:57 -050081 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -040082 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010083 .setLabel("Accept Suggestion")
84 .setCustomId("accept")
TheCodedProf21c08592022-09-13 14:14:43 -040085 .setStyle(ButtonStyle.Success)
Skyler Grey75ea9172022-08-06 10:22:23 +010086 .setDisabled(predicted[channel].length === 0)
Skyler Greyda16adf2023-03-05 10:22:12 +000087 .setEmoji(
88 client.emojis.cache.get(getEmojiByName("ICONS.TICK", "id")) as APIMessageComponentEmoji
89 ),
TheCodedProf21c08592022-09-13 14:14:43 -040090 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010091 .setLabel('Use "Other"')
92 .setCustomId("reject")
TheCodedProf21c08592022-09-13 14:14:43 -040093 .setStyle(ButtonStyle.Secondary)
Skyler Greyda16adf2023-03-05 10:22:12 +000094 .setEmoji(
95 client.emojis.cache.get(getEmojiByName("ICONS.CROSS", "id")) as APIMessageComponentEmoji
96 )
Skyler Grey75ea9172022-08-06 10:22:23 +010097 ])
98 ]
99 });
pineafan73a7c4a2022-07-24 10:38:04 +0100100 let i;
101 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000102 i = await m.awaitMessageComponent({
103 time: 300000,
Skyler Greyda16adf2023-03-05 10:22:12 +0000104 filter: (i) => {
105 return (
106 i.user.id === interaction.user.id &&
107 i.channel!.id === interaction.channel!.id &&
108 i.message.id === m.id
109 );
110 }
PineaFan0d06edc2023-01-17 22:10:31 +0000111 });
pineafan73a7c4a2022-07-24 10:38:04 +0100112 } catch (e) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100113 return await interaction.editReply({
114 embeds: [
115 new EmojiEmbed()
TheCodedProf267563a2023-01-21 17:00:57 -0500116 .setTitle("Categorize")
Skyler Grey75ea9172022-08-06 10:22:23 +0100117 .setEmoji("CHANNEL.CATEGORY.DELETE")
118 .setStatus("Danger")
119 .setDescription(
120 `Select all types that apply to <#${channel}>.\n\n` +
Skyler Grey11236ba2022-08-08 21:13:33 +0100121 `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(
122 ", "
123 )}`
Skyler Grey75ea9172022-08-06 10:22:23 +0100124 )
125 .setFooter({ text: "Message timed out" })
126 ]
127 });
pineafan73a7c4a2022-07-24 10:38:04 +0100128 }
TheCodedProf267563a2023-01-21 17:00:57 -0500129 await i.deferUpdate();
pineafan73a7c4a2022-07-24 10:38:04 +0100130 let selected;
Skyler Grey75ea9172022-08-06 10:22:23 +0100131 if (i.customId === "select") {
132 selected = i.values;
133 }
134 if (i.customId === "accept") {
135 selected = predicted[channel];
136 }
137 if (i.customId === "reject") {
138 selected = ["other"];
139 }
TheCodedProf267563a2023-01-21 17:00:57 -0500140 categorized[channel] = selected;
pineafan73a7c4a2022-07-24 10:38:04 +0100141 }
TheCodedProf267563a2023-01-21 17:00:57 -0500142 console.log(categorized);
pineafan63fc5e22022-08-04 22:04:10 +0100143};
pineafanad54d752022-04-18 19:01:43 +0100144
PineaFan0d06edc2023-01-17 22:10:31 +0000145const check = () => {
pineafanad54d752022-04-18 19:01:43 +0100146 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100147};
pineafanad54d752022-04-18 19:01:43 +0100148
149export { command };
150export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100151export { check };