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:39:52 +02:00
1 parent 859b229181
commit 4643e9300d
11 files changed
+452 -8

No files matched your search

+28 -1
View File
@@ -11,6 +11,11 @@ import {
removeNotificationChannel,
setNotificationChannel,
} from '../src/database/repositories/notification-repository.js';
import {
clearRulesMessage,
getRulesMessage,
setRulesMessage,
} from '../src/database/repositories/rules-repository.js';
import {
castVote,
closePoll,
@@ -29,7 +34,7 @@ import {
const reset = () =>
getDatabase().exec(
'DELETE FROM tickets; DELETE FROM moderation_actions; DELETE FROM polls; DELETE FROM poll_votes; DELETE FROM notification_channels;',
'DELETE FROM tickets; DELETE FROM moderation_actions; DELETE FROM polls; DELETE FROM poll_votes; DELETE FROM notification_channels; DELETE FROM rules_messages;',
);
describe('ticket repository', () => {
@@ -187,3 +192,25 @@ describe('notification repository', () => {
assert.equal(removeNotificationChannel('g', 'release'), 0);
});
});
describe('rules repository', () => {
before(() => initDatabase(':memory:'));
after(() => closeDatabase());
beforeEach(reset);
it('keeps one rules message per guild and replaces it', () => {
setRulesMessage({ guildId: 'g', channelId: 'c1', messageId: 'm1', updatedBy: 'mod' });
setRulesMessage({ guildId: 'g', channelId: 'c1', messageId: 'm2', updatedBy: 'mod' });
const stored = getRulesMessage('g');
assert.equal(stored.message_id, 'm2');
assert.equal(stored.updated_by, 'mod');
assert.equal(getRulesMessage('other'), null);
});
it('forgets the message when it is cleared', () => {
setRulesMessage({ guildId: 'g', channelId: 'c1', messageId: 'm1' });
assert.equal(clearRulesMessage('g'), 1);
assert.equal(getRulesMessage('g'), null);
});
});