refactor(cmd/moderation): adding the tsconfig + eslint correction

This commit is contained in:
Raphael 2025-10-14 00:17:56 +02:00 committed by Raphaël
parent a0a9cac16d
commit eece230bab

View file

@ -1,6 +1,7 @@
import { MessageFlags, SlashCommandBuilder, ChannelType, CommandInteraction } from 'discord.js'; import { SlashCommandBuilder } from '@discordjs/builders';
import emoji from '../../../assets/emoji.json' assert { type: 'json' }; import { MessageFlags, ChannelType, TextChannel, ChatInputCommandInteraction } from 'discord.js';
import { isWhitelisted } from '../../lib/perm.ts'; import emoji from '../../../assets/emoji.json' with { type: 'json' };
import { isWhitelisted } from '../../lib/perm.js';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -12,33 +13,54 @@ export default {
.setDescription('Choose the channel you want to renew') .setDescription('Choose the channel you want to renew')
.addChannelTypes(ChannelType.GuildText), .addChannelTypes(ChannelType.GuildText),
), ),
async execute(interaction: CommandInteraction) { async execute(interaction: ChatInputCommandInteraction) {
if (!interaction.guild) {
await interaction.reply({
content: `${emoji.answer.error} | This command can only be used in a server.`,
flags: MessageFlags.Ephemeral,
});
return;
}
if (!(await isWhitelisted(interaction.user.id, interaction.guild.id))) { if (!(await isWhitelisted(interaction.user.id, interaction.guild.id))) {
interaction.reply({ await interaction.reply({
content: `${emoji.answer.no} | You're not whitelisted on this server`, content: `${emoji.answer.no} | You're not whitelisted on this server`,
flags: MessageFlags.Ephemeral, flags: MessageFlags.Ephemeral,
}); });
return; return;
} }
const oldChannel : ChannelType.GuildText = interaction.options.getChannel( const oldChannel = (interaction.options.getChannel('channel') ?? interaction.channel) as TextChannel | null;
'channel', if (!oldChannel) {
) || interaction.channel; await interaction.reply({
content: `${emoji.answer.error} | Invalid or missing text channel.`,
flags: MessageFlags.Ephemeral,
});
return;
}
const pos: number = oldChannel.position; const pos: number = oldChannel.position;
oldChannel.clone().then((newchannel) => { try {
newchannel.setPosition(pos); const newchannel = await oldChannel.clone();
interaction.client.channels.fetch(newchannel.id).then( await newchannel.setPosition(pos);
channel => channel.send({ const fetchedChannel = await interaction.client.channels.fetch(
content: `${emoji.answer.yes} | ${newchannel} has been nuked by \`${interaction.user.username}\``, newchannel.id,
ephermal: true,
}),
); );
try { if (
oldChannel.delete(); fetchedChannel &&
fetchedChannel.type === ChannelType.GuildText &&
typeof (fetchedChannel as TextChannel).send === 'function'
) {
await (fetchedChannel as TextChannel).send({
content: `${emoji.answer.yes} | ${newchannel.toString()} has been nuked by \`${interaction.user.username}\``,
});
} }
catch (err) { await oldChannel.delete();
console.error(`⚠️ | Error when suppressing the channel\n\t${err}`); }
} catch (err) {
}); console.error(`⚠️ | Error when nuking the channel\n\t${err as Error}`);
await interaction.reply({
content: `${emoji.answer.no} | An error occurred while nuking the channel.`,
flags: MessageFlags.Ephemeral,
});
}
}, },
}; };