feat(settings): make the server settings real, and widen them
The dashboard offered seven switches that nothing read: they promised a behaviour the bot did not have, which is worse than offering nothing. Every setting is now declared once, with its type, its bounds and its explanation, and the services read it: the welcome message and its wording, the automatic role, departure notices, the private notice sent to a sanctioned member, the default mute duration, how much history a ban erases, whether a closed ticket is deleted or archived, and an optional role mention on the Gitea notifications. A test walks the sources and fails when a declared key is read nowhere, so the list cannot drift back into decoration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
13 files changed
+576
-146
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||||
import { readSetting } from '../../config/guild-settings.js';
|
||||
import {
|
||||
assertModerationTarget,
|
||||
logModerationAction,
|
||||
notifyTarget,
|
||||
targetNoticeEmbed,
|
||||
} from '../../services/moderation/moderation-service.js';
|
||||
import { successEmbed } from '../../ui/embeds.js';
|
||||
@@ -27,16 +29,17 @@ export const data = new SlashCommandBuilder()
|
||||
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;
|
||||
// Falls back to what the server configured rather than to a blunt zero.
|
||||
const deleteDays =
|
||||
interaction.options.getInteger('delete_days') ??
|
||||
Math.round(readSetting('moderation.banDeleteMessageHours', interaction.guildId) / 24);
|
||||
|
||||
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 notifyTarget(member, {
|
||||
embeds: [targetNoticeEmbed({ action: 'ban', guildName: interaction.guild.name, reason })],
|
||||
});
|
||||
}
|
||||
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
assertModerationTarget,
|
||||
fetchTargetMember,
|
||||
logModerationAction,
|
||||
notifyTarget,
|
||||
targetNoticeEmbed,
|
||||
} from '../../services/moderation/moderation-service.js';
|
||||
import { successEmbed } from '../../ui/embeds.js';
|
||||
@@ -26,11 +27,9 @@ export async function execute(interaction) {
|
||||
assertModerationTarget(interaction, target);
|
||||
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
await target
|
||||
.send({
|
||||
embeds: [targetNoticeEmbed({ action: 'kick', guildName: interaction.guild.name, reason })],
|
||||
})
|
||||
.catch(() => {});
|
||||
await notifyTarget(target, {
|
||||
embeds: [targetNoticeEmbed({ action: 'kick', guildName: interaction.guild.name, reason })],
|
||||
});
|
||||
await target.kick(reason ?? `Expulsion demandée par ${interaction.user.tag}`);
|
||||
|
||||
await logModerationAction(interaction, { action: 'kick', targetId: target.id, reason });
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { ACCESS_LEVELS } from '../../config/constants.js';
|
||||
import { readSetting } from '../../config/guild-settings.js';
|
||||
import {
|
||||
assertModerationTarget,
|
||||
fetchTargetMember,
|
||||
formatDuration,
|
||||
logModerationAction,
|
||||
notifyTarget,
|
||||
targetNoticeEmbed,
|
||||
} from '../../services/moderation/moderation-service.js';
|
||||
import { successEmbed } from '../../ui/embeds.js';
|
||||
@@ -20,7 +22,6 @@ export const data = new SlashCommandBuilder()
|
||||
option
|
||||
.setName('minutes')
|
||||
.setDescription('Durée de la sanction, en minutes')
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
.setMaxValue(40_320),
|
||||
)
|
||||
@@ -29,7 +30,9 @@ export const data = new SlashCommandBuilder()
|
||||
/** Applies a Discord timeout after the hierarchy checks (M8-T02 / M8-T07). */
|
||||
export async function execute(interaction) {
|
||||
const user = interaction.options.getUser('user', true);
|
||||
const minutes = interaction.options.getInteger('minutes', true);
|
||||
const minutes =
|
||||
interaction.options.getInteger('minutes') ??
|
||||
readSetting('moderation.defaultMuteMinutes', interaction.guildId);
|
||||
const reason = interaction.options.getString('reason');
|
||||
const durationMs = minutes * 60_000;
|
||||
|
||||
@@ -45,11 +48,9 @@ export async function execute(interaction) {
|
||||
reason,
|
||||
durationMs,
|
||||
});
|
||||
await target
|
||||
.send({
|
||||
embeds: [targetNoticeEmbed({ action: 'mute', guildName: interaction.guild.name, reason, durationMs })],
|
||||
})
|
||||
.catch(() => {});
|
||||
await notifyTarget(target, {
|
||||
embeds: [targetNoticeEmbed({ action: 'mute', guildName: interaction.guild.name, reason, durationMs })],
|
||||
});
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
assertModerationTarget,
|
||||
fetchTargetMember,
|
||||
logModerationAction,
|
||||
notifyTarget,
|
||||
targetNoticeEmbed,
|
||||
} from '../../services/moderation/moderation-service.js';
|
||||
import { successEmbed } from '../../ui/embeds.js';
|
||||
@@ -32,16 +33,14 @@ export async function execute(interaction) {
|
||||
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 notifyTarget(target, {
|
||||
embeds: [
|
||||
targetNoticeEmbed({ action: 'warn', guildName: interaction.guild.name, reason }).addFields({
|
||||
name: 'Avertissements',
|
||||
value: String(total),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
|
||||
Reference in new issue
Block a user