refactor(all): uniformisation
This commit is contained in:
89 files changed
+10215
-10215
No files matched your search
@@ -1,55 +1,55 @@
|
||||
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { ACCESS_LEVELS, COLORS, MODERATION_ACTIONS } from '../../config/constants.js';
|
||||
import { listActions } from '../../database/repositories/moderation-repository.js';
|
||||
import { formatDuration } from '../../services/moderation/moderation-service.js';
|
||||
import { baseEmbed, infoEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.STAFF;
|
||||
|
||||
const HISTORY_LIMIT = 15;
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName('mod')
|
||||
.setDescription('Outils de modération')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
|
||||
.addSubcommand((sub) =>
|
||||
sub
|
||||
.setName('logs')
|
||||
.setDescription('Consulter les actions de modération')
|
||||
.addUserOption((option) => option.setName('user').setDescription('Filtrer par membre')),
|
||||
);
|
||||
|
||||
function formatEntry(row) {
|
||||
const meta = MODERATION_ACTIONS[row.action];
|
||||
const target = row.target_id ? `<@${row.target_id}>` : 'salon';
|
||||
const duration = row.duration_ms ? ` pendant ${formatDuration(row.duration_ms)}` : '';
|
||||
return (
|
||||
`\`${row.created_at}\` **${meta?.label ?? row.action}** — ${target}${duration}\n` +
|
||||
`↳ par <@${row.moderator_id}> · ${row.reason || 'sans motif'}`
|
||||
);
|
||||
}
|
||||
|
||||
/** Reads the moderation history from SQLite (M8-T06). */
|
||||
export async function execute(interaction) {
|
||||
const user = interaction.options.getUser('user');
|
||||
const actions = listActions({
|
||||
guildId: interaction.guildId,
|
||||
targetId: user?.id ?? null,
|
||||
limit: HISTORY_LIMIT,
|
||||
});
|
||||
|
||||
const embed =
|
||||
actions.length === 0
|
||||
? infoEmbed(
|
||||
'📜 Historique de modération',
|
||||
user
|
||||
? `Rien à signaler concernant ${user} : aucune action de modération enregistrée.`
|
||||
: 'Aucune action de modération enregistrée sur ce serveur, tout est calme.',
|
||||
)
|
||||
: baseEmbed(COLORS.moderation)
|
||||
.setTitle(user ? `📜 Historique de ${user.tag}` : '📜 Dernières actions de modération')
|
||||
.setDescription(actions.map(formatEntry).join('\n\n'))
|
||||
.setFooter({ text: `${actions.length} action(s) affichée(s)` });
|
||||
|
||||
await interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral });
|
||||
}
|
||||
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { ACCESS_LEVELS, COLORS, MODERATION_ACTIONS } from '../../config/constants.js';
|
||||
import { listActions } from '../../database/repositories/moderation-repository.js';
|
||||
import { formatDuration } from '../../services/moderation/moderation-service.js';
|
||||
import { baseEmbed, infoEmbed } from '../../ui/embeds.js';
|
||||
|
||||
export const access = ACCESS_LEVELS.STAFF;
|
||||
|
||||
const HISTORY_LIMIT = 15;
|
||||
|
||||
export const data = new SlashCommandBuilder()
|
||||
.setName('mod')
|
||||
.setDescription('Outils de modération')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
|
||||
.addSubcommand((sub) =>
|
||||
sub
|
||||
.setName('logs')
|
||||
.setDescription('Consulter les actions de modération')
|
||||
.addUserOption((option) => option.setName('user').setDescription('Filtrer par membre')),
|
||||
);
|
||||
|
||||
function formatEntry(row) {
|
||||
const meta = MODERATION_ACTIONS[row.action];
|
||||
const target = row.target_id ? `<@${row.target_id}>` : 'salon';
|
||||
const duration = row.duration_ms ? ` pendant ${formatDuration(row.duration_ms)}` : '';
|
||||
return (
|
||||
`\`${row.created_at}\` **${meta?.label ?? row.action}** — ${target}${duration}\n` +
|
||||
`↳ par <@${row.moderator_id}> · ${row.reason || 'sans motif'}`
|
||||
);
|
||||
}
|
||||
|
||||
/** Reads the moderation history from SQLite (M8-T06). */
|
||||
export async function execute(interaction) {
|
||||
const user = interaction.options.getUser('user');
|
||||
const actions = listActions({
|
||||
guildId: interaction.guildId,
|
||||
targetId: user?.id ?? null,
|
||||
limit: HISTORY_LIMIT,
|
||||
});
|
||||
|
||||
const embed =
|
||||
actions.length === 0
|
||||
? infoEmbed(
|
||||
'📜 Historique de modération',
|
||||
user
|
||||
? `Rien à signaler concernant ${user} : aucune action de modération enregistrée.`
|
||||
: 'Aucune action de modération enregistrée sur ce serveur, tout est calme.',
|
||||
)
|
||||
: baseEmbed(COLORS.moderation)
|
||||
.setTitle(user ? `📜 Historique de ${user.tag}` : '📜 Dernières actions de modération')
|
||||
.setDescription(actions.map(formatEntry).join('\n\n'))
|
||||
.setFooter({ text: `${actions.length} action(s) affichée(s)` });
|
||||
|
||||
await interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral });
|
||||
}
|
||||
Reference in new issue
Block a user