Implement lockdown management in automod system

- Added functionality to activate and deactivate lockdowns via the automod worker, responding to specific job names.
- Enhanced the anti-raid join handler to apply a verification role when lockdown is active and the anti-raid action is set to VERIFY.
- Updated the automod configuration to ensure default rules are created if missing, improving the setup process for new guilds.
- Introduced new API endpoints for managing cases and warnings, allowing for soft deletion and reason updates.
- Enhanced the moderation dashboard to include warnings management, improving user experience in moderation tasks.
- Updated localization files to reflect new features and improve user guidance in both English and German.
This commit is contained in:
smueller
2026-07-24 10:21:49 +02:00
parent fba597a6f2
commit bd1b55fff7
22 changed files with 1517 additions and 242 deletions

View File

@@ -1,7 +1,9 @@
import { CaseListQuerySchema } from '@nexumi/shared';
import { CaseListQuerySchema, CaseUpdateDashboardSchema } from '@nexumi/shared';
import { type NextRequest, NextResponse } from 'next/server';
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
import { listCases } from '@/lib/module-configs/cases';
import { writeDashboardAudit } from '@/lib/audit';
import { listCases, softDeleteCase, updateCaseReason } from '@/lib/module-configs/cases';
import { prisma } from '@/lib/prisma';
interface RouteParams {
params: Promise<{ guildId: string }>;
@@ -11,15 +13,63 @@ export async function GET(request: NextRequest, { params }: RouteParams) {
const { guildId } = await params;
try {
await requireGuildAccess(guildId);
const searchParams = request.nextUrl.searchParams;
const query = CaseListQuerySchema.parse({
search: searchParams.get('search') ?? undefined,
action: searchParams.get('action') ?? undefined,
limit: searchParams.get('limit') ?? undefined
});
const query = CaseListQuerySchema.parse(Object.fromEntries(request.nextUrl.searchParams));
const cases = await listCases(guildId, query);
return NextResponse.json({ cases });
} catch (error) {
return toApiErrorResponse(error);
}
}
export async function PATCH(request: NextRequest, { params }: RouteParams) {
const { guildId } = await params;
try {
const session = await requireGuildAccess(guildId);
const body = (await request.json()) as { id?: string; reason?: string };
if (!body.id) {
return NextResponse.json({ error: 'Missing case id' }, { status: 400 });
}
const patch = CaseUpdateDashboardSchema.parse({ reason: body.reason });
const updated = await updateCaseReason(guildId, body.id, patch);
if (!updated) {
return NextResponse.json({ error: 'Case not found' }, { status: 404 });
}
await writeDashboardAudit(prisma, {
guildId,
actorUserId: session.user.id,
action: 'case.update',
path: `/dashboard/${guildId}/moderation`,
before: { id: body.id },
after: updated
});
return NextResponse.json({ case: updated });
} catch (error) {
return toApiErrorResponse(error);
}
}
export async function DELETE(request: NextRequest, { params }: RouteParams) {
const { guildId } = await params;
try {
const session = await requireGuildAccess(guildId);
const id = request.nextUrl.searchParams.get('id');
if (!id) {
return NextResponse.json({ error: 'Missing case id' }, { status: 400 });
}
const ok = await softDeleteCase(guildId, id);
if (!ok) {
return NextResponse.json({ error: 'Case not found' }, { status: 404 });
}
await writeDashboardAudit(prisma, {
guildId,
actorUserId: session.user.id,
action: 'case.delete',
path: `/dashboard/${guildId}/moderation`,
before: { id },
after: { deleted: true }
});
return NextResponse.json({ ok: true });
} catch (error) {
return toApiErrorResponse(error);
}
}