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