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) => { |
| 13 | // @ts-ignore |
| 14 | const { renderChannel } = interaction.client.logger |
| 15 | |
| 16 | let channels = interaction.guild.channels.cache.filter(c => c.type !== "GUILD_CATEGORY"); |
| 17 | let categorised = {} |
| 18 | |
| 19 | await interaction.reply({embeds: [new generateEmojiEmbed() |
| 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 | |
| 44 | await interaction.editReply({embeds: [new generateEmojiEmbed() |
| 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) |
| 63 | // .setMaxValues(Object.keys(types).length) |
| 64 | .setOptions(Object.keys(types).map(type => {return {label: toCapitals(type), value: type}})) |
| 65 | ])]}); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | export { command }; |
| 74 | export { callback }; |
| 75 | export { check }; |