blob: dfe90983037a2f917f1140f7678566c32b378a13 [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;
pineafan63fc5e22022-08-04 22:04:10 +010054 if (!predicted[channel]) predicted[channel] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +010055 m = await interaction.editReply({
56 embeds: [
57 new EmojiEmbed()
TheCodedProf267563a2023-01-21 17:00:57 -050058 .setTitle("Categorize")
Skyler Grey75ea9172022-08-06 10:22:23 +010059 .setDescription(
60 `Select all types that apply to <#${channel}>.\n\n` +
Skyler Grey11236ba2022-08-08 21:13:33 +010061 `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(", ")}`
Skyler Grey75ea9172022-08-06 10:22:23 +010062 )
63 .setEmoji("CHANNEL.CATEGORY.CREATE")
64 .setStatus("Success")
65 ],
66 components: [
TheCodedProf267563a2023-01-21 17:00:57 -050067 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
68 new StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010069 .setCustomId("selected")
70 .setMaxValues(Object.keys(types).length)
71 .setMinValues(1)
Skyler Grey11236ba2022-08-08 21:13:33 +010072 .setPlaceholder("Select all types that apply to this channel")
Skyler Grey75ea9172022-08-06 10:22:23 +010073 .setOptions(
74 Object.keys(types).map((type) => ({
75 label: type,
76 value: type
77 }))
78 )
79 ]),
TheCodedProf267563a2023-01-21 17:00:57 -050080 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -040081 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010082 .setLabel("Accept Suggestion")
83 .setCustomId("accept")
TheCodedProf21c08592022-09-13 14:14:43 -040084 .setStyle(ButtonStyle.Success)
Skyler Grey75ea9172022-08-06 10:22:23 +010085 .setDisabled(predicted[channel].length === 0)
Skyler Greyda16adf2023-03-05 10:22:12 +000086 .setEmoji(
87 client.emojis.cache.get(getEmojiByName("ICONS.TICK", "id")) as APIMessageComponentEmoji
88 ),
TheCodedProf21c08592022-09-13 14:14:43 -040089 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010090 .setLabel('Use "Other"')
91 .setCustomId("reject")
TheCodedProf21c08592022-09-13 14:14:43 -040092 .setStyle(ButtonStyle.Secondary)
Skyler Greyda16adf2023-03-05 10:22:12 +000093 .setEmoji(
94 client.emojis.cache.get(getEmojiByName("ICONS.CROSS", "id")) as APIMessageComponentEmoji
95 )
Skyler Grey75ea9172022-08-06 10:22:23 +010096 ])
97 ]
98 });
pineafan73a7c4a2022-07-24 10:38:04 +010099 let i;
100 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000101 i = await m.awaitMessageComponent({
102 time: 300000,
Skyler Greyda16adf2023-03-05 10:22:12 +0000103 filter: (i) => {
104 return (
105 i.user.id === interaction.user.id &&
106 i.channel!.id === interaction.channel!.id &&
107 i.message.id === m.id
108 );
109 }
PineaFan0d06edc2023-01-17 22:10:31 +0000110 });
pineafan73a7c4a2022-07-24 10:38:04 +0100111 } catch (e) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100112 return await interaction.editReply({
113 embeds: [
114 new EmojiEmbed()
TheCodedProf267563a2023-01-21 17:00:57 -0500115 .setTitle("Categorize")
Skyler Grey75ea9172022-08-06 10:22:23 +0100116 .setEmoji("CHANNEL.CATEGORY.DELETE")
117 .setStatus("Danger")
118 .setDescription(
119 `Select all types that apply to <#${channel}>.\n\n` +
Skyler Grey11236ba2022-08-08 21:13:33 +0100120 `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(
121 ", "
122 )}`
Skyler Grey75ea9172022-08-06 10:22:23 +0100123 )
124 .setFooter({ text: "Message timed out" })
125 ]
126 });
pineafan73a7c4a2022-07-24 10:38:04 +0100127 }
TheCodedProf267563a2023-01-21 17:00:57 -0500128 await i.deferUpdate();
pineafan73a7c4a2022-07-24 10:38:04 +0100129 let selected;
Skyler Grey75ea9172022-08-06 10:22:23 +0100130 if (i.customId === "select") {
131 selected = i.values;
132 }
133 if (i.customId === "accept") {
134 selected = predicted[channel];
135 }
136 if (i.customId === "reject") {
137 selected = ["other"];
138 }
TheCodedProf267563a2023-01-21 17:00:57 -0500139 categorized[channel] = selected;
pineafan73a7c4a2022-07-24 10:38:04 +0100140 }
pineafan63fc5e22022-08-04 22:04:10 +0100141};
pineafanad54d752022-04-18 19:01:43 +0100142
PineaFan0d06edc2023-01-17 22:10:31 +0000143const check = () => {
pineafanad54d752022-04-18 19:01:43 +0100144 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100145};
pineafanad54d752022-04-18 19:01:43 +0100146
147export { command };
148export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100149export { check };