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
@@ -0,0 +1,23 @@
|
||||
-- Lifted sanctions join the sanctions in the moderation history
|
||||
--
|
||||
-- `/unmute` and `/unban` are recorded like `/mute` and `/ban`, but SQLite cannot
|
||||
-- alter a CHECK constraint: the table is rebuilt and the rows copied over so the
|
||||
-- history already stored survives the migration.
|
||||
|
||||
CREATE TABLE moderation_actions_lifted (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
guild_id TEXT NOT NULL,
|
||||
action TEXT NOT NULL CHECK (action IN ('warn', 'mute', 'unmute', 'kick', 'ban', 'unban', 'clear', 'role')),
|
||||
target_id TEXT,
|
||||
moderator_id TEXT NOT NULL,
|
||||
reason TEXT,
|
||||
duration_ms INTEGER,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
INSERT INTO moderation_actions_lifted (id, guild_id, action, target_id, moderator_id, reason, duration_ms, created_at)
|
||||
SELECT id, guild_id, action, target_id, moderator_id, reason, duration_ms, created_at FROM moderation_actions;
|
||||
|
||||
DROP TABLE moderation_actions;
|
||||
ALTER TABLE moderation_actions_lifted RENAME TO moderation_actions;
|
||||
CREATE INDEX IF NOT EXISTS idx_moderation_target ON moderation_actions (guild_id, target_id);
|
||||
Reference in new issue
Block a user