feat(rules): write the rules from the dashboard and republish them

The rules lived in a channel nobody but a staff member with a shell could
edit, and the welcome message pointed at it. They are now written in
markdown under Settings and published as a single pinned embed, and a new
publication deletes the message the bot posted last time instead of
piling copies up in the channel.
This commit is contained in:
BlackAngelTV committed 2026-09-25 20:44:29 +02:00
1 parent 20ffbbacad
commit 31c0fc861a
11 files changed
+452 -8

No files matched your search

+35
View File
@@ -1,6 +1,7 @@
import { ChannelType, REST, Routes } from 'discord.js';
import { ACCESS_LABELS, ACCESS_LEVELS } from '../../config/constants.js';
import { env } from '../../config/env.js';
import { readSetting, writeSetting } from '../../config/guild-settings.js';
import { ExternalApiError } from '../../core/errors.js';
import { createLogger } from '../../core/logger.js';
import { canActOn, getAccessLevel } from '../../core/permissions.js';
@@ -16,6 +17,7 @@ import {
setNotificationChannel,
} from '../../database/repositories/notification-repository.js';
import { moderationLabel, sendModerationLog } from '../../services/moderation/moderation-service.js';
import { publishRules, rulesStatus } from '../../services/rules/rules-service.js';
import { badRequest, forbidden, notFound } from '../http.js';
/** Discord server management from the dashboard (M16-T05). */
@@ -292,6 +294,39 @@ export function registerDiscordRoutes(router) {
{ access: ACCESS_LEVELS.STAFF },
);
// --- Server rules ----------------------------------------------------------
router.get(
'/api/discord/rules',
() => ({ markdown: readSetting('rules.markdown', guildId()), ...rulesStatus(guildId()) }),
{ access: ACCESS_LEVELS.STAFF },
);
/** Publishes the rules, replacing the message the bot posted last time. */
router.post(
'/api/discord/rules',
async ({ context, body, actor }) => {
const markdown = writeSetting('rules.markdown', body.markdown, {
guildId: guildId(),
updatedBy: actor.userId,
});
try {
const published = await publishRules(context.client, {
guildId: guildId(),
markdown,
actorId: actor.userId,
});
return { ok: true, ...published, ...rulesStatus(guildId()) };
} catch (error) {
// The text is saved either way: a channel that is simply not configured
// yet must not throw away what was written.
throw badRequest(error.message);
}
},
{ access: ACCESS_LEVELS.DEV },
);
// --- Notification routing --------------------------------------------------
router.get(
'/api/discord/notifications',