refactor(all): uniformisation
This commit is contained in:
89 files changed
+10215
-10215
No files matched your search
@@ -1,53 +1,53 @@
|
||||
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||||
import { countActions } from '../../database/repositories/moderation-repository.js';
|
||||
import {
|
||||
assertModerationTarget,
|
||||
fetchTargetMember,
|
||||
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('warn')
|
||||
.setDescription('Avertir un membre')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
|
||||
.addUserOption((option) => option.setName('user').setDescription('Membre').setRequired(true))
|
||||
.addStringOption((option) =>
|
||||
option.setName('reason').setDescription('Motif').setRequired(true).setMaxLength(500),
|
||||
);
|
||||
|
||||
/** Records the warning, notifies the member and logs it (M8-T01 / M8-T06). */
|
||||
export async function execute(interaction) {
|
||||
const user = interaction.options.getUser('user', true);
|
||||
const reason = interaction.options.getString('reason', true);
|
||||
|
||||
const target = await fetchTargetMember(interaction, user.id);
|
||||
assertModerationTarget(interaction, target);
|
||||
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
await logModerationAction(interaction, { action: 'warn', targetId: target.id, reason });
|
||||
|
||||
const total = countActions({ guildId: interaction.guildId, targetId: target.id, action: 'warn' });
|
||||
await target
|
||||
.send({
|
||||
embeds: [
|
||||
targetNoticeEmbed({ action: 'warn', guildName: interaction.guild.name, reason }).addFields({
|
||||
name: 'Avertissements',
|
||||
value: String(total),
|
||||
}),
|
||||
],
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
successEmbed(
|
||||
`C’est fait : **${target.user.tag}** reçoit un avertissement (${total} au total). La personne a aussi reçu un message privé quand c’était possible.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
}
|
||||
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||||
import { countActions } from '../../database/repositories/moderation-repository.js';
|
||||
import {
|
||||
assertModerationTarget,
|
||||
fetchTargetMember,
|
||||
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('warn')
|
||||
.setDescription('Avertir un membre')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
|
||||
.addUserOption((option) => option.setName('user').setDescription('Membre').setRequired(true))
|
||||
.addStringOption((option) =>
|
||||
option.setName('reason').setDescription('Motif').setRequired(true).setMaxLength(500),
|
||||
);
|
||||
|
||||
/** Records the warning, notifies the member and logs it (M8-T01 / M8-T06). */
|
||||
export async function execute(interaction) {
|
||||
const user = interaction.options.getUser('user', true);
|
||||
const reason = interaction.options.getString('reason', true);
|
||||
|
||||
const target = await fetchTargetMember(interaction, user.id);
|
||||
assertModerationTarget(interaction, target);
|
||||
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
await logModerationAction(interaction, { action: 'warn', targetId: target.id, reason });
|
||||
|
||||
const total = countActions({ guildId: interaction.guildId, targetId: target.id, action: 'warn' });
|
||||
await target
|
||||
.send({
|
||||
embeds: [
|
||||
targetNoticeEmbed({ action: 'warn', guildName: interaction.guild.name, reason }).addFields({
|
||||
name: 'Avertissements',
|
||||
value: String(total),
|
||||
}),
|
||||
],
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
successEmbed(
|
||||
`C’est fait : **${target.user.tag}** reçoit un avertissement (${total} au total). La personne a aussi reçu un message privé quand c’était possible.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user