Update ESLint rules, enhance environment schema with new metrics and health port, and refactor Redis import. Change TypeScript definitions path in package.json.
This commit is contained in:
47
apps/bot/src/modules/moderation/service.ts
Normal file
47
apps/bot/src/modules/moderation/service.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { moderationQueue } from '../../jobs.js';
|
||||
import type { BotContext } from '../../types.js';
|
||||
|
||||
type CreateCaseInput = {
|
||||
guildId: string;
|
||||
targetUserId: string;
|
||||
moderatorId: string;
|
||||
action: string;
|
||||
reason?: string;
|
||||
metadata?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export async function createCase(context: BotContext, input: CreateCaseInput) {
|
||||
const lastCase = await context.prisma.case.findFirst({
|
||||
where: { guildId: input.guildId },
|
||||
orderBy: { caseNumber: 'desc' }
|
||||
});
|
||||
|
||||
return context.prisma.case.create({
|
||||
data: {
|
||||
guildId: input.guildId,
|
||||
caseNumber: (lastCase?.caseNumber ?? 0) + 1,
|
||||
targetUserId: input.targetUserId,
|
||||
moderatorId: input.moderatorId,
|
||||
action: input.action,
|
||||
reason: input.reason,
|
||||
metadata: input.metadata
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function scheduleTempBanExpire(
|
||||
guildId: string,
|
||||
userId: string,
|
||||
durationMs: number,
|
||||
reason?: string
|
||||
) {
|
||||
await moderationQueue.add(
|
||||
'tempBanExpire',
|
||||
{ guildId, userId, reason: reason ?? null },
|
||||
{
|
||||
delay: durationMs,
|
||||
removeOnComplete: 1000,
|
||||
removeOnFail: 500
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user