Enhance bot functionality with new features and improvements
- Updated package dependencies to include `@sentry/node` for error tracking. - Refactored command routing to incorporate user and guild blacklisting checks, improving command execution safety. - Enhanced health server metrics to include queue waiting times, providing better insights into system performance. - Introduced confirmation handling for guild backup commands, streamlining user interactions. - Improved moderation commands with better error handling and case management, ensuring robust moderation capabilities. - Added new duration parsing functions to handle timeout durations effectively, enhancing moderation features. - Updated localization files to reflect new command structures and user guidance improvements.
This commit is contained in:
@@ -6,7 +6,17 @@ import {
|
||||
getCaptchaChallenge,
|
||||
hashCaptchaAnswer
|
||||
} from './modules/verification/service.js';
|
||||
import { verificationQueue } from './queues.js';
|
||||
import {
|
||||
automodQueue,
|
||||
backupQueue,
|
||||
birthdayQueue,
|
||||
feedsQueue,
|
||||
presenceQueue,
|
||||
retentionQueue,
|
||||
ticketQueue,
|
||||
verificationQueue
|
||||
} from './queues.js';
|
||||
import { collectMetricsSnapshot, formatPrometheus } from './metrics.js';
|
||||
|
||||
function readBody(req: IncomingMessage): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -99,6 +109,19 @@ async function handleCaptchaPost(req: IncomingMessage, res: ServerResponse): Pro
|
||||
res.end('<html><body style="font-family:sans-serif;background:#111827;color:#f9fafb;display:flex;justify-content:center;align-items:center;min-height:100vh"><div><h1>Verified</h1><p>You can return to Discord.</p></div></body></html>');
|
||||
}
|
||||
|
||||
async function approximateQueueWaiting(): Promise<number> {
|
||||
const counts = await Promise.all([
|
||||
automodQueue.getWaitingCount(),
|
||||
backupQueue.getWaitingCount(),
|
||||
birthdayQueue.getWaitingCount(),
|
||||
feedsQueue.getWaitingCount(),
|
||||
presenceQueue.getWaitingCount(),
|
||||
retentionQueue.getWaitingCount(),
|
||||
ticketQueue.getWaitingCount()
|
||||
]);
|
||||
return counts.reduce((sum, n) => sum + n, 0);
|
||||
}
|
||||
|
||||
export function startHealthServer(): void {
|
||||
const server = createServer(async (req, res) => {
|
||||
if (!req.url) {
|
||||
@@ -121,8 +144,16 @@ export function startHealthServer(): void {
|
||||
res.end('Unauthorized');
|
||||
return;
|
||||
}
|
||||
res.statusCode = 200;
|
||||
res.end('# Prometheus metrics scaffold\nnexumi_up 1\n');
|
||||
try {
|
||||
const snapshot = await collectMetricsSnapshot(redis);
|
||||
snapshot.queueWaiting = await approximateQueueWaiting();
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'text/plain; version=0.0.4; charset=utf-8');
|
||||
res.end(formatPrometheus(snapshot));
|
||||
} catch {
|
||||
res.statusCode = 500;
|
||||
res.end('metrics error');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user