feat(moderation): add the unmute and unban commands
A sanction could be applied but never lifted from Discord, so undoing a mistake meant leaving the bot for the server settings. Both lifts are recorded next to the sanctions they lift, which means widening the moderation history CHECK constraint through a table rebuild. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
8 files changed
+162
-2
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { after, before, describe, it } from 'node:test';
|
||||
import { closeDatabase, getDatabase, initDatabase } from '../src/database/index.js';
|
||||
import { listActions, recordAction } from '../src/database/repositories/moderation-repository.js';
|
||||
import { getSetting, setSetting } from '../src/database/repositories/settings-repository.js';
|
||||
|
||||
describe('database', () => {
|
||||
@@ -22,6 +23,20 @@ describe('database', () => {
|
||||
assert.equal(getSetting('guild-b', 'welcome'), null);
|
||||
});
|
||||
|
||||
it('records a lifted sanction next to the sanction it lifts', () => {
|
||||
// `/unmute` and `/unban` go through the same CHECK constraint as `/mute`
|
||||
// and `/ban`, so a migration that forgets them breaks the history.
|
||||
for (const action of ['unban', 'unmute']) {
|
||||
recordAction({ guildId: 'g', action, moderatorId: 'mod', targetId: 'u', reason: 'Erreur' });
|
||||
}
|
||||
|
||||
const rows = listActions({ guildId: 'g', targetId: 'u' });
|
||||
assert.deepEqual(
|
||||
rows.map((row) => row.action).sort(),
|
||||
['unban', 'unmute'],
|
||||
);
|
||||
});
|
||||
|
||||
it('prevents two open tickets for the same author and category', () => {
|
||||
const insert = getDatabase().prepare(
|
||||
"INSERT INTO tickets (guild_id, category_id, author_id) VALUES ('g', 'bug', 'u')",
|
||||
|
||||
Reference in new issue
Block a user