feat(moderation): implement the moderation service and commands
Every action checks the role hierarchy before touching Discord, then records the sanction in SQLite and mirrors it in the moderation log channel, so the history outlives the audit log.
This commit is contained in:
9 files changed
+460
-30
No files matched your search
@@ -1,9 +1,13 @@
|
||||
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||||
import { notImplementedEmbed } from '../../ui/embeds.js';
|
||||
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')
|
||||
@@ -15,7 +19,35 @@ export const data = new SlashCommandBuilder()
|
||||
.addUserOption((option) => option.setName('user').setDescription('Filtrer par membre')),
|
||||
);
|
||||
|
||||
// TODO(M8-T06): read from moderation_actions.
|
||||
export async function execute(interaction) {
|
||||
await interaction.reply({ embeds: [notImplementedEmbed('/mod logs')] });
|
||||
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 raison'}`
|
||||
);
|
||||
}
|
||||
|
||||
/** 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 ? `Aucune action enregistrée contre ${user}.` : 'Aucune action enregistrée sur ce serveur.',
|
||||
)
|
||||
: 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} dernière(s) action(s)` });
|
||||
|
||||
await interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral });
|
||||
}
|
||||
Reference in new issue
Block a user