Enhance bot functionality with AutoMod, Logging, Welcome, and Verification features
- Implemented AutoMod capabilities including spam filtering, anti-raid, and anti-nuke actions. - Added Logging module to track moderation actions and events across the bot. - Introduced Welcome module for customizable welcome messages and autoroles. - Developed Verification system with captcha and role assignment features. - Updated Prisma schema to include new models for AutoMod, Logging, Welcome, and Verification. - Enhanced command localization for new features in both German and English. - Improved health server to handle captcha verification requests. - Added new environment variable for public base URL to support captcha links.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Queue, Worker } from 'bullmq';
|
||||
import { Worker } from 'bullmq';
|
||||
import { PermissionFlagsBits } from 'discord.js';
|
||||
import { mkdir, readdir, rm, stat } from 'node:fs/promises';
|
||||
import { basename, join } from 'node:path';
|
||||
@@ -7,11 +7,24 @@ import { redis } from './redis.js';
|
||||
import { logger } from './logger.js';
|
||||
import type { BotContext } from './types.js';
|
||||
import { env } from './env.js';
|
||||
import { refreshPhishingDomains } from './modules/automod/filters.js';
|
||||
import { completeVerification } from './modules/verification/handlers.js';
|
||||
import {
|
||||
automodQueue,
|
||||
automodQueueName,
|
||||
backupQueue,
|
||||
backupQueueName,
|
||||
moderationQueueName,
|
||||
verificationQueueName
|
||||
} from './queues.js';
|
||||
|
||||
export const moderationQueueName = 'moderation';
|
||||
export const moderationQueue = new Queue(moderationQueueName, { connection: redis });
|
||||
export const backupQueueName = 'backups';
|
||||
export const backupQueue = new Queue(backupQueueName, { connection: redis });
|
||||
export {
|
||||
automodQueue,
|
||||
backupQueue,
|
||||
moderationQueue,
|
||||
moderationQueueName,
|
||||
verificationQueue
|
||||
} from './queues.js';
|
||||
|
||||
type TempBanJob = {
|
||||
guildId: string;
|
||||
@@ -19,6 +32,11 @@ type TempBanJob = {
|
||||
reason: string | null;
|
||||
};
|
||||
|
||||
type VerificationCompleteJob = {
|
||||
guildId: string;
|
||||
userId: string;
|
||||
};
|
||||
|
||||
export function startWorkers(context: BotContext): Worker[] {
|
||||
const moderationWorker = new Worker<TempBanJob>(
|
||||
moderationQueueName,
|
||||
@@ -56,7 +74,38 @@ export function startWorkers(context: BotContext): Worker[] {
|
||||
logger.error({ jobId: job?.id, error }, 'Backup job failed');
|
||||
});
|
||||
|
||||
return [moderationWorker, backupWorker];
|
||||
const automodWorker = new Worker(
|
||||
automodQueueName,
|
||||
async (job) => {
|
||||
if (job.name !== 'refreshPhishingList') {
|
||||
return;
|
||||
}
|
||||
const count = await refreshPhishingDomains(redis);
|
||||
logger.info({ domainCount: count }, 'Phishing domain list refreshed');
|
||||
},
|
||||
{ connection: redis }
|
||||
);
|
||||
|
||||
automodWorker.on('failed', (job, error) => {
|
||||
logger.error({ jobId: job?.id, error }, 'AutoMod job failed');
|
||||
});
|
||||
|
||||
const verificationWorker = new Worker<VerificationCompleteJob>(
|
||||
verificationQueueName,
|
||||
async (job) => {
|
||||
if (job.name !== 'verificationComplete') {
|
||||
return;
|
||||
}
|
||||
await completeVerification(context, job.data.guildId, job.data.userId);
|
||||
},
|
||||
{ connection: redis }
|
||||
);
|
||||
|
||||
verificationWorker.on('failed', (job, error) => {
|
||||
logger.error({ jobId: job?.id, error }, 'Verification job failed');
|
||||
});
|
||||
|
||||
return [moderationWorker, backupWorker, automodWorker, verificationWorker];
|
||||
}
|
||||
|
||||
export async function ensureRecurringJobs(): Promise<void> {
|
||||
@@ -69,6 +118,18 @@ export async function ensureRecurringJobs(): Promise<void> {
|
||||
removeOnFail: 100
|
||||
}
|
||||
);
|
||||
|
||||
await automodQueue.add(
|
||||
'refreshPhishingList',
|
||||
{},
|
||||
{
|
||||
repeat: { pattern: '0 */6 * * *' },
|
||||
removeOnComplete: 20,
|
||||
removeOnFail: 20
|
||||
}
|
||||
);
|
||||
|
||||
await automodQueue.add('refreshPhishingList', {}, { removeOnComplete: 20, removeOnFail: 20 });
|
||||
}
|
||||
|
||||
async function runPgDumpBackup(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user