refactor(all): uniformisation
This commit is contained in:
89 files changed
+10215
-10215
No files matched your search
@@ -1,56 +1,56 @@
|
||||
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||||
import {
|
||||
assertModerationTarget,
|
||||
logModerationAction,
|
||||
targetNoticeEmbed,
|
||||
} from '../../services/moderation/moderation-service.js';
|
||||
import { successEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.STAFF;
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName('ban')
|
||||
.setDescription('Bannir un membre')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
|
||||
.addUserOption((option) => option.setName('user').setDescription('Membre').setRequired(true))
|
||||
.addStringOption((option) => option.setName('reason').setDescription('Motif').setMaxLength(500))
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('delete_days')
|
||||
.setDescription('Supprimer aussi les messages des N derniers jours (0 à 7)')
|
||||
.setMinValue(0)
|
||||
.setMaxValue(7),
|
||||
);
|
||||
|
||||
/** Bans the user, whether or not they are still on the server (M8-T04 / M8-T09). */
|
||||
export async function execute(interaction) {
|
||||
const user = interaction.options.getUser('user', true);
|
||||
const reason = interaction.options.getString('reason');
|
||||
const deleteDays = interaction.options.getInteger('delete_days') ?? 0;
|
||||
|
||||
const member = await interaction.guild.members.fetch(user.id).catch(() => null);
|
||||
if (member) {
|
||||
assertModerationTarget(interaction, member);
|
||||
await member
|
||||
.send({
|
||||
embeds: [targetNoticeEmbed({ action: 'ban', guildName: interaction.guild.name, reason })],
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
await interaction.guild.bans.create(user.id, {
|
||||
reason: reason ?? `Bannissement demandé par ${interaction.user.tag}`,
|
||||
deleteMessageSeconds: deleteDays * 86_400,
|
||||
});
|
||||
|
||||
await logModerationAction(interaction, { action: 'ban', targetId: user.id, reason });
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
successEmbed(
|
||||
`C’est fait : **${user.tag}** ne peut plus revenir sur le serveur. L’historique reste consultable avec \`/mod logs\`.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
}
|
||||
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||||
import {
|
||||
assertModerationTarget,
|
||||
logModerationAction,
|
||||
targetNoticeEmbed,
|
||||
} from '../../services/moderation/moderation-service.js';
|
||||
import { successEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.STAFF;
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName('ban')
|
||||
.setDescription('Bannir un membre')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
|
||||
.addUserOption((option) => option.setName('user').setDescription('Membre').setRequired(true))
|
||||
.addStringOption((option) => option.setName('reason').setDescription('Motif').setMaxLength(500))
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('delete_days')
|
||||
.setDescription('Supprimer aussi les messages des N derniers jours (0 à 7)')
|
||||
.setMinValue(0)
|
||||
.setMaxValue(7),
|
||||
);
|
||||
|
||||
/** Bans the user, whether or not they are still on the server (M8-T04 / M8-T09). */
|
||||
export async function execute(interaction) {
|
||||
const user = interaction.options.getUser('user', true);
|
||||
const reason = interaction.options.getString('reason');
|
||||
const deleteDays = interaction.options.getInteger('delete_days') ?? 0;
|
||||
|
||||
const member = await interaction.guild.members.fetch(user.id).catch(() => null);
|
||||
if (member) {
|
||||
assertModerationTarget(interaction, member);
|
||||
await member
|
||||
.send({
|
||||
embeds: [targetNoticeEmbed({ action: 'ban', guildName: interaction.guild.name, reason })],
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
await interaction.guild.bans.create(user.id, {
|
||||
reason: reason ?? `Bannissement demandé par ${interaction.user.tag}`,
|
||||
deleteMessageSeconds: deleteDays * 86_400,
|
||||
});
|
||||
|
||||
await logModerationAction(interaction, { action: 'ban', targetId: user.id, reason });
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
successEmbed(
|
||||
`C’est fait : **${user.tag}** ne peut plus revenir sur le serveur. L’historique reste consultable avec \`/mod logs\`.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user