2023-01-17 23:11:22 +01:00
|
|
|
import { SlashCommandBuilder } from "@discordjs/builders";
|
|
|
|
import {
|
|
|
|
ChannelType,
|
|
|
|
Client,
|
|
|
|
Colors,
|
|
|
|
CommandInteraction,
|
|
|
|
EmbedBuilder,
|
|
|
|
NonThreadGuildBasedChannel,
|
|
|
|
} from "discord.js";
|
|
|
|
import "../../modules/string";
|
|
|
|
import { getLocale, getLocalizations } from "../../utils/locales";
|
|
|
|
import { getFilename } from "../../utils/misc";
|
2023-01-17 14:28:59 +01:00
|
|
|
|
|
|
|
export default {
|
2023-01-17 23:11:22 +01:00
|
|
|
scope: () => ["807244911350906920"],
|
2023-01-17 22:05:38 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
data: (client: Client) => {
|
|
|
|
const filename = getFilename(__filename);
|
|
|
|
return (
|
|
|
|
new SlashCommandBuilder()
|
|
|
|
.setName(filename.toLowerCase())
|
2024-09-17 11:36:24 +02:00
|
|
|
.setDescription(client.locales.get(client.config.default_lang)!.get(`c_${filename}_desc`)!)
|
2023-01-17 23:11:22 +01:00
|
|
|
.setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true))
|
|
|
|
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`))
|
2023-01-17 14:28:59 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
// Command option
|
|
|
|
.addStringOption((option) =>
|
|
|
|
option
|
|
|
|
.setName(
|
2024-09-17 11:36:24 +02:00
|
|
|
client.locales.get(client.config.default_lang)!.get(`c_${filename}_opt1_name`)!,
|
2023-01-17 23:11:22 +01:00
|
|
|
)
|
|
|
|
.setDescription(
|
2024-09-17 11:36:24 +02:00
|
|
|
client.locales.get(client.config.default_lang)!.get(`c_${filename}_opt1_desc`)!,
|
2023-01-17 23:11:22 +01:00
|
|
|
)
|
|
|
|
.setNameLocalizations(getLocalizations(client, `c_${filename}_opt1_name`, true))
|
2024-04-02 00:11:54 +02:00
|
|
|
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`)),
|
2023-01-17 23:11:22 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
2023-01-17 14:28:59 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
interaction: async (interaction: CommandInteraction, client: Client) => {
|
|
|
|
const loc = getLocale(client, interaction.locale);
|
|
|
|
const desiredCat = interaction.options.get(
|
|
|
|
client.locales
|
2024-09-17 11:36:24 +02:00
|
|
|
.get(client.config.default_lang)!
|
|
|
|
.get(`c_${getFilename(__filename)}_opt1_name`)!,
|
2023-01-17 23:11:22 +01:00
|
|
|
)?.value as string;
|
2023-01-17 14:28:59 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
// If a category isn't specified
|
|
|
|
if (!desiredCat) {
|
|
|
|
// Sends a list of commands sorted into categories
|
|
|
|
return interaction.reply({
|
|
|
|
embeds: [
|
|
|
|
new EmbedBuilder()
|
|
|
|
.setColor(Colors.Blurple)
|
|
|
|
.setTitle(loc.get("c_archive1"))
|
|
|
|
.setDescription(loc.get("c_archive2")),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
2023-01-17 14:28:59 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
// If a category is specified
|
|
|
|
const cleanCat = ["L1", "L2", "L3", "M1", "M2"];
|
|
|
|
const channel = cleanCat.includes(desiredCat);
|
|
|
|
if (!channel) {
|
|
|
|
// Category doesn't exist or is not included
|
|
|
|
return interaction.reply({
|
|
|
|
content: `${loc.get("c_archive3")} \`${desiredCat}\``,
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
2023-01-17 14:28:59 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
const allChannel = interaction.guild?.channels.fetch();
|
|
|
|
allChannel?.then(async (channelGuild) => {
|
|
|
|
// Retrieve category to archive
|
|
|
|
const catToArchive = channelGuild
|
2024-09-18 18:25:03 +02:00
|
|
|
.filter((chan) => chan?.type === ChannelType.GuildCategory)
|
|
|
|
.filter((chan) => chan?.name === desiredCat);
|
2023-01-17 14:28:59 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
// Create/Retrieve the archive category
|
|
|
|
const catArchivedName = "archive - " + desiredCat;
|
|
|
|
const catArchivedMap = channelGuild
|
2024-09-18 18:25:03 +02:00
|
|
|
.filter((chan) => chan?.type === ChannelType.GuildCategory)
|
|
|
|
.filter((chan) => chan?.name === catArchivedName);
|
2023-01-17 22:05:38 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
let catArchived: NonThreadGuildBasedChannel | null | undefined;
|
|
|
|
if (catArchivedMap.size > 0) {
|
|
|
|
catArchived = catArchivedMap.at(0);
|
|
|
|
} else {
|
|
|
|
catArchived = await interaction.guild?.channels.create({
|
|
|
|
name: catArchivedName,
|
|
|
|
type: ChannelType.GuildCategory,
|
|
|
|
});
|
|
|
|
}
|
2023-01-17 14:28:59 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
const allChannelDesired = channelGuild
|
2024-09-18 18:25:03 +02:00
|
|
|
.filter((chan) => chan?.type === 0)
|
|
|
|
.filter((chan) => chan?.parentId === catToArchive.map((cat) => cat?.id)[0]);
|
2023-01-17 22:05:38 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
// If no channels in the source category
|
2024-09-18 18:25:03 +02:00
|
|
|
if (allChannelDesired.size === 0) {
|
2023-01-17 23:11:22 +01:00
|
|
|
return interaction.reply({
|
|
|
|
embeds: [
|
|
|
|
new EmbedBuilder()
|
|
|
|
.setColor(Colors.Blurple)
|
|
|
|
.setTitle(loc.get("c_archive6"))
|
|
|
|
.setDescription(loc.get("c_archive7")),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
2023-01-17 14:28:59 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
// Move channels to the archived categoryx
|
|
|
|
allChannelDesired.forEach((elem) => elem?.setParent(catArchived?.id as string));
|
2023-01-17 14:28:59 +01:00
|
|
|
|
2023-01-17 23:11:22 +01:00
|
|
|
return interaction.reply({
|
|
|
|
embeds: [
|
|
|
|
new EmbedBuilder()
|
|
|
|
.setColor(Colors.Blurple)
|
|
|
|
.setTitle(
|
|
|
|
loc.get("c_archive4") +
|
|
|
|
" `" +
|
|
|
|
catToArchive.map((cat) => cat?.name) +
|
|
|
|
"` " +
|
|
|
|
loc.get("c_archive5") +
|
|
|
|
" `" +
|
|
|
|
catArchivedName +
|
2024-04-02 00:11:54 +02:00
|
|
|
"`",
|
2023-01-17 23:11:22 +01:00
|
|
|
)
|
|
|
|
.setDescription(
|
|
|
|
allChannelDesired
|
|
|
|
.map((cgD) => cgD?.name)
|
|
|
|
.toString()
|
2024-04-02 00:11:54 +02:00
|
|
|
.replaceAll(",", "\n"),
|
2023-01-17 23:11:22 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2023-01-17 14:28:59 +01:00
|
|
|
};
|