pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 1 | import { CommandInteraction, MessageActionRow, MessageButton, MessageSelectMenu } from "discord.js"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 2 | import { SlashCommandBuilder } from "@discordjs/builders"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 3 | import { WrappedCheck } from "jshaiku"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 4 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 5 | import generateKeyValueList, { toCapitals } from "../utils/generateKeyValueList.js"; |
| 6 | import getEmojiByName from "../utils/getEmojiByName.js"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 7 | import client from "../utils/client.js" |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 8 | |
| 9 | const command = new SlashCommandBuilder() |
| 10 | .setName("categorise") |
| 11 | .setDescription("Categorises your servers channels") |
| 12 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 13 | const callback = async (interaction: CommandInteraction): Promise<any> => { |
PineappleFan | b3dd83c | 2022-06-17 10:53:48 +0100 | [diff] [blame] | 14 | const { renderChannel } = client.logger |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 15 | |
| 16 | let channels = interaction.guild.channels.cache.filter(c => c.type !== "GUILD_CATEGORY"); |
| 17 | let categorised = {} |
| 18 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 19 | await interaction.reply({embeds: [new EmojiEmbed() |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 20 | .setTitle("Loading...") |
| 21 | .setEmoji("NUCLEUS.LOADING") |
| 22 | .setStatus("Success") |
| 23 | ], ephemeral: true}); |
| 24 | for (let c of channels.values()) { |
| 25 | let predicted = [] |
| 26 | let types = { |
| 27 | general: ["general"], |
| 28 | commands: ["bot", "command", "music"], |
| 29 | images: ["pic", "selfies", "image"], |
| 30 | nsfw: ["porn", "nsfw", "sex"], |
| 31 | links: ["links"], |
| 32 | advertising: ["ads", "advert", "server", "partner"], |
| 33 | staff: ["staff", "mod", "admin"] |
| 34 | } |
| 35 | |
| 36 | for (let type in types) { |
| 37 | for (let word of types[type]) { |
| 38 | if (c.name.toLowerCase().includes(word)) { |
| 39 | predicted.push(type) |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 44 | await interaction.editReply({embeds: [new EmojiEmbed() |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 45 | .setTitle("Categorise") |
| 46 | .setDescription(generateKeyValueList({ |
| 47 | channel: renderChannel(c), |
| 48 | category: c.parent ? c.parent.name : "Uncategorised" |
| 49 | }) + "\n\n" + `Suggested tags: ${predicted.join(", ")}`) |
| 50 | .setEmoji("CHANNEL.TEXT.CREATE") |
| 51 | .setStatus("Success") |
| 52 | ], components: [ new MessageActionRow().addComponents([ |
| 53 | new MessageButton() |
| 54 | .setLabel("Use suggested") |
| 55 | .setStyle("PRIMARY") |
| 56 | .setCustomId("accept") |
| 57 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
| 58 | ]), new MessageActionRow().addComponents([new MessageSelectMenu() |
| 59 | .setPlaceholder("Select a category") |
| 60 | .setCustomId("category") |
| 61 | .setMinValues(0) |
| 62 | .setMaxValues(1) |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 63 | .setOptions(Object.keys(types).map(type => {return {label: toCapitals(type), value: type}})) |
| 64 | ])]}); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | export { command }; |
| 73 | export { callback }; |
| 74 | export { check }; |