pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "../utils/defaultEmbeds.js"; |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 2 | import { CommandInteraction, GuildChannel, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, ButtonStyle } from "discord.js"; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 3 | import { SlashCommandBuilder } from "@discordjs/builders"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 4 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | import client from "../utils/client.js"; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 6 | import addPlural from "../utils/plurals.js"; |
| 7 | import getEmojiByName from "../utils/getEmojiByName.js"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 8 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 9 | const command = new SlashCommandBuilder().setName("categorise").setDescription("Categorises your servers channels"); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 10 | |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 11 | const callback = async (interaction: CommandInteraction): Promise<unknown> => { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 12 | const channels = interaction.guild.channels.cache.filter((c) => c.type !== "GUILD_CATEGORY"); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | const categorised = {}; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 14 | await interaction.reply({ embeds: LoadingEmbed, ephemeral: true }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | const predicted = {}; |
| 16 | const types = { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 17 | general: ["general", "muted", "main", "topic", "discuss"], |
| 18 | commands: ["bot", "command", "music"], |
| 19 | images: ["pic", "selfies", "image"], |
| 20 | nsfw: ["porn", "nsfw", "sex"], |
| 21 | links: ["links"], |
| 22 | advertising: ["ads", "advert", "server", "partner"], |
| 23 | staff: ["staff", "mod", "admin"], |
| 24 | spam: ["spam"], |
| 25 | other: ["random"] |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 26 | }; |
| 27 | for (const c of channels.values()) { |
| 28 | for (const type in types) { |
| 29 | for (const word of types[type]) { |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 30 | if (c.name.toLowerCase().includes(word)) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 31 | predicted[c.id] = predicted[c.id] ?? []; |
| 32 | predicted[c.id].push(type); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | } |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 36 | } |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 37 | let m; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 38 | for (const c of channels) { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 39 | // convert channel to a channel if its a string |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 40 | let channel: string | GuildChannel; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 41 | if (typeof c === "string") channel = interaction.guild.channels.cache.get(channel as string).id; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 42 | else channel = (c[0] as unknown as GuildChannel).id; |
| 43 | console.log(channel); |
| 44 | if (!predicted[channel]) predicted[channel] = []; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 45 | m = await interaction.editReply({ |
| 46 | embeds: [ |
| 47 | new EmojiEmbed() |
| 48 | .setTitle("Categorise") |
| 49 | .setDescription( |
| 50 | `Select all types that apply to <#${channel}>.\n\n` + |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 51 | `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(", ")}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 52 | ) |
| 53 | .setEmoji("CHANNEL.CATEGORY.CREATE") |
| 54 | .setStatus("Success") |
| 55 | ], |
| 56 | components: [ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 57 | new ActionRowBuilder().addComponents([ |
| 58 | new SelectMenuBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 59 | .setCustomId("selected") |
| 60 | .setMaxValues(Object.keys(types).length) |
| 61 | .setMinValues(1) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 62 | .setPlaceholder("Select all types that apply to this channel") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 63 | .setOptions( |
| 64 | Object.keys(types).map((type) => ({ |
| 65 | label: type, |
| 66 | value: type |
| 67 | })) |
| 68 | ) |
| 69 | ]), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 70 | new ActionRowBuilder().addComponents([ |
| 71 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 72 | .setLabel("Accept Suggestion") |
| 73 | .setCustomId("accept") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 74 | .setStyle(ButtonStyle.Success) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 75 | .setDisabled(predicted[channel].length === 0) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 76 | .setEmoji(client.emojis.cache.get(getEmojiByName("ICONS.TICK", "id"))), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 77 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 78 | .setLabel('Use "Other"') |
| 79 | .setCustomId("reject") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 80 | .setStyle(ButtonStyle.Secondary) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 81 | .setEmoji(client.emojis.cache.get(getEmojiByName("ICONS.CROSS", "id"))) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 82 | ]) |
| 83 | ] |
| 84 | }); |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 85 | let i; |
| 86 | try { |
| 87 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 88 | } catch (e) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 89 | return await interaction.editReply({ |
| 90 | embeds: [ |
| 91 | new EmojiEmbed() |
| 92 | .setTitle("Categorise") |
| 93 | .setEmoji("CHANNEL.CATEGORY.DELETE") |
| 94 | .setStatus("Danger") |
| 95 | .setDescription( |
| 96 | `Select all types that apply to <#${channel}>.\n\n` + |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 97 | `${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join( |
| 98 | ", " |
| 99 | )}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 100 | ) |
| 101 | .setFooter({ text: "Message timed out" }) |
| 102 | ] |
| 103 | }); |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 104 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 105 | i.deferUpdate(); |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 106 | let selected; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 107 | if (i.customId === "select") { |
| 108 | selected = i.values; |
| 109 | } |
| 110 | if (i.customId === "accept") { |
| 111 | selected = predicted[channel]; |
| 112 | } |
| 113 | if (i.customId === "reject") { |
| 114 | selected = ["other"]; |
| 115 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 116 | categorised[channel] = selected; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 117 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 118 | console.log(categorised); |
| 119 | }; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 120 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame^] | 121 | const check = (_interaction: CommandInteraction) => { |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 122 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 123 | }; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 124 | |
| 125 | export { command }; |
| 126 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 127 | export { check }; |