fix issues
This commit is contained in:
parent
c999421479
commit
cb00362a82
1 changed files with 42 additions and 29 deletions
|
@ -1,8 +1,8 @@
|
||||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||||
import { ChannelType, Client, CommandInteraction, EmbedBuilder } from 'discord.js';
|
import { CategoryChannelResolvable, ChannelType, Client, CommandInteraction, EmbedBuilder, NonThreadGuildBasedChannel } from 'discord.js';
|
||||||
|
import '../../modules/string';
|
||||||
import { getLocale, getLocalizations } from '../../utils/locales';
|
import { getLocale, getLocalizations } from '../../utils/locales';
|
||||||
import { getFilename } from '../../utils/misc';
|
import { getFilename } from '../../utils/misc';
|
||||||
import '../../modules/string';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: (client: Client) => {
|
data: (client: Client) => {
|
||||||
|
@ -32,13 +32,13 @@ export default {
|
||||||
|
|
||||||
interaction: async (interaction: CommandInteraction, client: Client) => {
|
interaction: async (interaction: CommandInteraction, client: Client) => {
|
||||||
const loc = getLocale(client, interaction.locale);
|
const loc = getLocale(client, interaction.locale);
|
||||||
const desired_cat = interaction.options.get(client
|
const desiredCat = interaction.options.get(client
|
||||||
.locales
|
.locales
|
||||||
.get(client.config.default_lang)
|
.get(client.config.default_lang)
|
||||||
?.get(`c_${getFilename(__filename)}_opt1_name`) ?? '')?.value as string;
|
?.get(`c_${getFilename(__filename)}_opt1_name`) ?? '')?.value as string;
|
||||||
|
|
||||||
// If a category isn't specified
|
// If a category isn't specified
|
||||||
if (!desired_cat) {
|
if (!desiredCat) {
|
||||||
|
|
||||||
// Sends a list of commands sorted into categories
|
// Sends a list of commands sorted into categories
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
|
@ -52,58 +52,71 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a category is specified
|
// If a category is specified
|
||||||
const clean_cat = ['L1', 'L2', 'L3', 'M1', 'M2'];
|
const cleanCat = ['L1', 'L2', 'L3', 'M1', 'M2'];
|
||||||
const channel = clean_cat.includes(desired_cat);
|
const channel = cleanCat.includes(desiredCat);
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
// Category doesn't exist or is not included
|
// Category doesn't exist or is not included
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
content: `${loc.get('c_archive3')} \`${desired_cat}\``,
|
content: `${loc.get('c_archive3')} \`${desiredCat}\``,
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send information about the command
|
|
||||||
const allChannel = interaction.guild?.channels.fetch();
|
const allChannel = interaction.guild?.channels.fetch();
|
||||||
allChannel?.then(channel_guild => {
|
allChannel?.then(async channelGuild => {
|
||||||
const cat_to_archive = channel_guild.filter(chan => chan.type == ChannelType.GuildCategory).filter(chan => chan.name == desired_cat);
|
// Retrieve category to archive
|
||||||
const cat_to_archive_id = cat_to_archive.map(cat => cat.id);
|
const catToArchive = channelGuild
|
||||||
const cat_to_archive_name = cat_to_archive.map(cat => cat.name);
|
.filter(chan => chan?.type == ChannelType.GuildCategory)
|
||||||
|
.filter(chan => chan?.name == desiredCat);
|
||||||
|
|
||||||
const cat_archived = channel_guild.filter(chan => chan.type == ChannelType.GuildCategory).filter(chan => chan.name == 'archive - ' + desired_cat);
|
// Create/Retrieve the archive category
|
||||||
const cat_archived_id = cat_archived.map(cat => cat.id);
|
const catArchivedName = 'archive - ' + desiredCat;
|
||||||
const cat_archived_name = cat_archived.map(cat => cat.name);
|
const getCatArchived = () => channelGuild
|
||||||
|
.filter(chan => chan?.type == ChannelType.GuildCategory)
|
||||||
|
.filter(chan => chan?.name == catArchivedName);
|
||||||
|
|
||||||
const all_channel_desired = channel_guild.filter(chan => chan.type == 0).filter(chan => chan.parentId == cat_to_archive_id[0]);
|
if (getCatArchived().size == 0) {
|
||||||
if (all_channel_desired.size == 0) {
|
await interaction.guild?.channels
|
||||||
|
.create({ name: catArchivedName, type: ChannelType.GuildCategory });
|
||||||
|
}
|
||||||
|
const catArchived = getCatArchived().at(0);
|
||||||
|
|
||||||
|
const allChannelDesired = channelGuild
|
||||||
|
.filter(chan => chan?.type == 0)
|
||||||
|
.filter(chan => chan?.parentId == catToArchive.map(cat => cat?.id)[0]);
|
||||||
|
|
||||||
|
// If no channels in the source category
|
||||||
|
if (allChannelDesired.size == 0) {
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setColor('Blurple')
|
.setColor('Blurple')
|
||||||
.setTitle(loc.get('c_archive6'))
|
.setTitle(loc.get('c_archive6'))
|
||||||
.setDescription(
|
.setDescription(
|
||||||
// Loads the description
|
|
||||||
// according to the user's locals
|
|
||||||
loc.get('c_archive7')
|
loc.get('c_archive7')
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const all_channel_desired_name = all_channel_desired.map(cg_d => cg_d.name);
|
|
||||||
console.log(all_channel_desired_name);
|
|
||||||
all_channel_desired.forEach(elem =>
|
|
||||||
elem.setParent(cat_archived_id[0])
|
|
||||||
);
|
|
||||||
|
|
||||||
const list_cg_moved = all_channel_desired_name.toString().replaceAll(',', '\n');
|
// Move channels to the archived category
|
||||||
|
allChannelDesired.forEach(elem => elem?.setParent(catArchived?.id as string));
|
||||||
|
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setColor('Blurple')
|
.setColor('Blurple')
|
||||||
.setTitle(loc.get('c_archive4') + cat_to_archive_name + loc.get('c_archive5') + cat_archived_name + '`')
|
.setTitle(loc.get('c_archive4')
|
||||||
|
+ '`'
|
||||||
|
+ catToArchive.map(cat => cat?.name)
|
||||||
|
+ '`'
|
||||||
|
+ loc.get('c_archive5')
|
||||||
|
+ '`'
|
||||||
|
+ catArchivedName
|
||||||
|
+ '`')
|
||||||
.setDescription(
|
.setDescription(
|
||||||
// Loads the description
|
allChannelDesired
|
||||||
// according to the user's locals
|
.map(cgD => cgD?.name).toString().replaceAll(',', '\n')
|
||||||
list_cg_moved
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue