A sanction could be applied but never lifted from Discord, so undoing a mistake meant leaving the bot for the server settings. Both lifts are recorded next to the sanctions they lift, which means widening the moderation history CHECK constraint through a table rebuild. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
53 lines
2.1 KiB
JavaScript
53 lines
2.1 KiB
JavaScript
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||
import { UserFacingError } from '../../core/errors.js';
|
||
import {
|
||
assertModerationTarget,
|
||
fetchTargetMember,
|
||
logModerationAction,
|
||
notifyTarget,
|
||
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('unmute')
|
||
.setDescription('Lever l’exclusion temporaire d’un membre avant la fin')
|
||
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
|
||
.addUserOption((option) => option.setName('user').setDescription('Membre').setRequired(true))
|
||
.addStringOption((option) => option.setName('reason').setDescription('Motif').setMaxLength(500));
|
||
|
||
/** Counterpart of `/mute`: clears the timeout early and keeps the trail. */
|
||
export async function execute(interaction) {
|
||
const user = interaction.options.getUser('user', true);
|
||
const reason = interaction.options.getString('reason');
|
||
|
||
const target = await fetchTargetMember(interaction, user.id);
|
||
assertModerationTarget(interaction, target);
|
||
// Discord answers a timeout removal on a member who is not muted with an
|
||
// opaque error, so the check turns it into an explicit message.
|
||
if (!target.isCommunicationDisabled()) {
|
||
throw new UserFacingError(
|
||
`${target.user.tag} n’est pas en exclusion temporaire : cette personne peut déjà écrire.`,
|
||
);
|
||
}
|
||
|
||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||
await target.timeout(null, reason ?? `Levée d’exclusion demandée par ${interaction.user.tag}`);
|
||
|
||
await logModerationAction(interaction, { action: 'unmute', targetId: target.id, reason });
|
||
await notifyTarget(target, {
|
||
embeds: [targetNoticeEmbed({ action: 'unmute', guildName: interaction.guild.name, reason })],
|
||
});
|
||
|
||
await interaction.editReply({
|
||
embeds: [
|
||
successEmbed(
|
||
`C’est fait : **${target.user.tag}** peut de nouveau écrire sur le serveur. L’historique reste consultable avec \`/mod logs\`.`,
|
||
),
|
||
],
|
||
});
|
||
}
|