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