blob: 2da2be3213d1504d994dd45258d46800613cc44e [file] [log] [blame]
import { LoadingEmbed } from "../utils/defaultEmbeds.js";
import { CommandInteraction, GuildChannel, MessageActionRow, MessageButton, MessageSelectMenu } from "discord.js";
import { SlashCommandBuilder } from "@discordjs/builders";
// @ts-expect-error
import type { WrappedCheck } from "jshaiku";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import client from "../utils/client.js";
import addPlural from "../utils/plurals.js";
import getEmojiByName from "../utils/getEmojiByName.js";
const command = new SlashCommandBuilder().setName("categorise").setDescription("Categorises your servers channels");
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const channels = interaction.guild.channels.cache.filter((c) => c.type !== "GUILD_CATEGORY");
const categorised = {};
await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
const predicted = {};
const types = {
general: ["general", "muted", "main", "topic", "discuss"],
commands: ["bot", "command", "music"],
images: ["pic", "selfies", "image"],
nsfw: ["porn", "nsfw", "sex"],
links: ["links"],
advertising: ["ads", "advert", "server", "partner"],
staff: ["staff", "mod", "admin"],
spam: ["spam"],
other: ["random"]
};
for (const c of channels.values()) {
for (const type in types) {
for (const word of types[type]) {
if (c.name.toLowerCase().includes(word)) {
predicted[c.id] = predicted[c.id] ?? [];
predicted[c.id].push(type);
}
}
}
}
let m;
for (const c of channels) {
// convert channel to a channel if its a string
let channel: string | GuildChannel;
if (typeof c === "string") channel = interaction.guild.channels.cache.get(channel as string).id;
else channel = (c[0] as unknown as GuildChannel).id;
console.log(channel);
if (!predicted[channel]) predicted[channel] = [];
m = await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Categorise")
.setDescription(
`Select all types that apply to <#${channel}>.\n\n` +
`${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(", ")}`
)
.setEmoji("CHANNEL.CATEGORY.CREATE")
.setStatus("Success")
],
components: [
new MessageActionRow().addComponents([
new MessageSelectMenu()
.setCustomId("selected")
.setMaxValues(Object.keys(types).length)
.setMinValues(1)
.setPlaceholder("Select all types that apply to this channel")
.setOptions(
Object.keys(types).map((type) => ({
label: type,
value: type
}))
)
]),
new MessageActionRow().addComponents([
new MessageButton()
.setLabel("Accept Suggestion")
.setCustomId("accept")
.setStyle("SUCCESS")
.setDisabled(predicted[channel].length === 0)
.setEmoji(client.emojis.cache.get(getEmojiByName("ICONS.TICK", "id"))),
new MessageButton()
.setLabel('Use "Other"')
.setCustomId("reject")
.setStyle("SECONDARY")
.setEmoji(client.emojis.cache.get(getEmojiByName("ICONS.CROSS", "id")))
])
]
});
let i;
try {
i = await m.awaitMessageComponent({ time: 300000 });
} catch (e) {
return await interaction.editReply({
embeds: [
new EmojiEmbed()
.setTitle("Categorise")
.setEmoji("CHANNEL.CATEGORY.DELETE")
.setStatus("Danger")
.setDescription(
`Select all types that apply to <#${channel}>.\n\n` +
`${addPlural(predicted[channel].length, "Suggestion")}: ${predicted[channel].join(
", "
)}`
)
.setFooter({ text: "Message timed out" })
]
});
}
i.deferUpdate();
let selected;
if (i.customId === "select") {
selected = i.values;
}
if (i.customId === "accept") {
selected = predicted[channel];
}
if (i.customId === "reject") {
selected = ["other"];
}
categorised[channel] = selected;
}
console.log(categorised);
};
const check = (_interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
return true;
};
export { command };
export { callback };
export { check };