Refactor moderation actions to include channel and source metadata
- Updated moderation action functions to include `channelId` and `source` in the metadata for better tracking of actions. - Introduced an `auditFrom` function to streamline the addition of audit information across various commands. - Removed `prisma/migrations` from .gitignore to ensure migration files are tracked. - Enhanced the `CreateCaseInput` type to accommodate new metadata structure.
This commit is contained in:
@@ -2,6 +2,7 @@ import { moderationQueue } from '../../jobs.js';
|
||||
import type { BotContext } from '../../types.js';
|
||||
import { PermissionFlagsBits, type ChatInputCommandInteraction } from 'discord.js';
|
||||
import type { Prisma } from '@prisma/client';
|
||||
import { buildCaseMetadata, type CaseAuditSource } from '@nexumi/shared';
|
||||
|
||||
type CreateCaseInput = {
|
||||
guildId: string;
|
||||
@@ -9,7 +10,9 @@ type CreateCaseInput = {
|
||||
moderatorId: string;
|
||||
action: string;
|
||||
reason?: string;
|
||||
metadata?: Prisma.InputJsonValue;
|
||||
source?: CaseAuditSource;
|
||||
channelId?: string;
|
||||
metadata?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export async function createCase(context: BotContext, input: CreateCaseInput) {
|
||||
@@ -24,6 +27,12 @@ export async function createCase(context: BotContext, input: CreateCaseInput) {
|
||||
orderBy: { caseNumber: 'desc' }
|
||||
});
|
||||
|
||||
const metadata = buildCaseMetadata({
|
||||
source: input.source ?? 'slash_command',
|
||||
channelId: input.channelId,
|
||||
extras: input.metadata
|
||||
});
|
||||
|
||||
return context.prisma.case.create({
|
||||
data: {
|
||||
guildId: input.guildId,
|
||||
@@ -32,7 +41,7 @@ export async function createCase(context: BotContext, input: CreateCaseInput) {
|
||||
moderatorId: input.moderatorId,
|
||||
action: input.action,
|
||||
reason: input.reason,
|
||||
metadata: input.metadata
|
||||
metadata: metadata as Prisma.InputJsonValue
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -94,6 +103,8 @@ export async function applyWarnEscalation(
|
||||
moderatorId,
|
||||
action: 'TIMEOUT',
|
||||
reason,
|
||||
channelId: interaction.channelId ?? undefined,
|
||||
source: 'escalation',
|
||||
metadata: { escalation: true, durationMs: rule.durationMs, warningCount }
|
||||
});
|
||||
return `Auto escalation applied: timeout (${rule.durationMs} ms).`;
|
||||
@@ -110,6 +121,8 @@ export async function applyWarnEscalation(
|
||||
moderatorId,
|
||||
action: 'KICK',
|
||||
reason,
|
||||
channelId: interaction.channelId ?? undefined,
|
||||
source: 'escalation',
|
||||
metadata: { escalation: true, warningCount }
|
||||
});
|
||||
return 'Auto escalation applied: kick.';
|
||||
@@ -125,6 +138,8 @@ export async function applyWarnEscalation(
|
||||
moderatorId,
|
||||
action: 'BAN',
|
||||
reason,
|
||||
channelId: interaction.channelId ?? undefined,
|
||||
source: 'escalation',
|
||||
metadata: { escalation: true, warningCount }
|
||||
});
|
||||
return 'Auto escalation applied: ban.';
|
||||
|
||||
Reference in New Issue
Block a user