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:
nocodeandClaude Opus 5 committed 2026-09-23 22:31:36 +02:00
1 parent d439b1b3e8
commit 52a5c50692
13 files changed
+576 -146

No files matched your search

+15 -2
View File
@@ -1,5 +1,6 @@
import { COLORS } from '../../config/constants.js';
import { env } from '../../config/env.js';
import { readSetting } from '../../config/guild-settings.js';
import { createLogger } from '../../core/logger.js';
import { logEvent } from '../../database/repositories/event-log-repository.js';
import { baseEmbed } from '../../ui/embeds.js';
@@ -14,6 +15,10 @@ async function sendTo(channel) {
/** Sends the welcome embed in `CHANNEL_WELCOME_ID` (M7-T01 / M7-T02). */
export async function sendWelcome(client, member) {
if (!readSetting('welcome.enabled', member.guild.id)) {
log.debug('Welcome message disabled for this guild');
return;
}
if (!env.channels.welcome) {
log.debug('No welcome channel configured');
return;
@@ -25,13 +30,17 @@ export async function sendWelcome(client, member) {
return;
}
const greeting =
readSetting('welcome.message', member.guild.id).replaceAll('{server}', member.guild.name) ||
DEFAULT_WELCOME;
const embed = baseEmbed(COLORS.primary)
.setTitle('🎉 Nouveau membre')
.setDescription(`${member} vient d’arriver. ${DEFAULT_WELCOME}`)
.setDescription(`${member} vient d’arriver. ${greeting}`)
.addFields({ name: 'Membres', value: String(member.guild.memberCount), inline: true })
.setThumbnail(member.user.displayAvatarURL({ size: 128 }));
if (env.channels.rules) {
if (env.channels.rules && readSetting('welcome.showRules', member.guild.id)) {
embed.addFields({ name: 'Règlement', value: `À lire ici : <#${env.channels.rules}>` });
}
@@ -41,6 +50,8 @@ export async function sendWelcome(client, member) {
/** Gives the default member role (M7-T03). */
export async function assignMemberRole(member) {
if (!readSetting('members.autoRole', member.guild.id)) return;
const roleId = env.roles.member;
if (!roleId || member.roles.cache.has(roleId)) return;
@@ -82,6 +93,8 @@ export async function sendWelcomeDirectMessage(member) {
/** Logs a departure in the log channel (M7-T04). */
export async function announceDeparture(client, member) {
if (!readSetting('departure.announce', member.guild.id)) return;
const channelId = env.channels.logs || env.channels.modLogs;
if (!channelId) return;
@@ -1,5 +1,6 @@
import { COLORS, MODERATION_ACTIONS } from '../../config/constants.js';
import { env } from '../../config/env.js';
import { readSetting } from '../../config/guild-settings.js';
import { UserFacingError } from '../../core/errors.js';
import { canActOn } from '../../core/permissions.js';
import { logEvent } from '../../database/repositories/event-log-repository.js';
@@ -95,6 +96,19 @@ export async function sendModerationLog(
await channel.send({ embeds: [embed] }).catch(() => {});
}
/**
* Sends the private notice to the sanctioned member, when the server wants one
* (M8-T07). Never throws: plenty of accounts refuse direct messages, and that
* must not turn a successful sanction into an error.
*/
export async function notifyTarget(member, payload) {
if (!readSetting('moderation.dmTarget', member.guild.id)) return false;
return member
.send(payload)
.then(() => true)
.catch(() => false);
}
/** Direct message sent to the member who is being moderated (M8-T07). */
export function targetNoticeEmbed({ action, guildName, reason = null, durationMs = null }) {
const meta = MODERATION_ACTIONS[action];
@@ -1,4 +1,5 @@
import { env } from '../../config/env.js';
import { readSetting } from '../../config/guild-settings.js';
import { createLogger } from '../../core/logger.js';
import { getNotificationChannel } from '../../database/repositories/notification-repository.js';
import { errorEmbed } from '../../ui/embeds.js';
@@ -58,7 +59,15 @@ export async function notify(client, type, payload) {
log.warn(`Notification channel unavailable for ${type}`, { channelId });
return null;
}
return channel.send(payload);
// An optional ping, prepended rather than replacing whatever content the
// caller already prepared.
const mention = readSetting('notifications.mentionRoleId');
const message = mention
? { ...payload, content: payload.content ? `<@&${mention}> ${payload.content}` : `<@&${mention}>` }
: payload;
return channel.send(message);
}
/** Reports an unexpected failure in the technical channel (M9-T07). */
+14 -2
View File
@@ -1,5 +1,6 @@
import { ChannelType, PermissionFlagsBits } from 'discord.js';
import { ACCESS_LEVELS, COLORS, TICKET_CATEGORIES } from '../../config/constants.js';
import { readSetting } from '../../config/guild-settings.js';
import { env } from '../../config/env.js';
import { PermissionDeniedError, UserFacingError } from '../../core/errors.js';
import { createLogger } from '../../core/logger.js';
@@ -235,10 +236,13 @@ export async function closeTicket(interaction, reason = null) {
payload: { ticketId: ticket.id, reason },
});
const deleteChannel = readSetting('tickets.deleteChannelOnClose', ticket.guild_id);
await interaction.reply({
embeds: [
successEmbed(
`Ticket fermé par <@${interaction.user.id}> — merci ! Le salon disparaît dans 10 secondes, tu as le temps de copier ce qui t’intéresse.`,
deleteChannel
? `Ticket fermé par <@${interaction.user.id}> — merci ! Le salon disparaît dans 10 secondes, tu as le temps de copier ce qui t’intéresse.`
: `Ticket fermé par <@${interaction.user.id}> — merci ! Le salon reste consultable, mais plus personne ne peut y écrire.`,
),
],
});
@@ -255,7 +259,15 @@ export async function closeTicket(interaction, reason = null) {
);
const channel = interaction.channel;
setTimeout(() => channel?.delete(`Ticket #${ticket.id} fermé`).catch(() => {}), 10_000).unref();
if (deleteChannel) {
setTimeout(() => channel?.delete(`Ticket #${ticket.id} fermé`).catch(() => {}), 10_000).unref();
return;
}
// Archived instead of deleted: the author keeps read access, nobody can write.
await channel?.permissionOverwrites
.edit(ticket.author_id, { SendMessages: false })
.catch(() => log.debug('Could not lock the closed ticket channel', { ticketId: ticket.id }));
}
/** Grants a staff member access to the ticket channel (M6-T07). */