Add suggestion status update job and queue integration
- Introduced a new `SuggestionStatusUpdateJob` type and corresponding worker to handle suggestion status updates in the bot's job processing. - Added `suggestionsQueue` and `suggestionsQueueEvents` for managing suggestion-related jobs in both the bot and WebUI. - Implemented `runSuggestionStatusUpdateJob` to facilitate staff actions on suggestions via the WebUI, ensuring consistent behavior with existing commands. - Enhanced error handling for suggestion actions to improve user experience and reliability.
This commit is contained in:
@@ -19,6 +19,7 @@ import { ensureStatsRecurringJobs, startStatsWorker } from './modules/stats/inde
|
||||
import { pollAllFeeds } from './modules/feeds/index.js';
|
||||
import { sendScheduledMessage } from './modules/scheduler/index.js';
|
||||
import { runGuildBackupRestoreJob } from './modules/guildbackup/index.js';
|
||||
import { runSuggestionStatusUpdateJob } from './modules/suggestions/index.js';
|
||||
import {
|
||||
automodQueue,
|
||||
automodQueueName,
|
||||
@@ -33,6 +34,7 @@ import {
|
||||
moderationQueueName,
|
||||
reminderQueueName,
|
||||
scheduleQueueName,
|
||||
suggestionsQueueName,
|
||||
ticketQueue,
|
||||
ticketQueueName,
|
||||
verificationQueueName
|
||||
@@ -95,6 +97,13 @@ type BirthdayRoleExpireJob = {
|
||||
roleId: string;
|
||||
};
|
||||
|
||||
type SuggestionStatusUpdateJob = {
|
||||
suggestionId: string;
|
||||
guildId: string;
|
||||
status: 'OPEN' | 'APPROVED' | 'DENIED' | 'CONSIDERED' | 'IMPLEMENTED';
|
||||
reason: string;
|
||||
};
|
||||
|
||||
export function startWorkers(context: BotContext): Worker[] {
|
||||
const moderationWorker = new Worker<TempBanJob>(
|
||||
moderationQueueName,
|
||||
@@ -281,6 +290,20 @@ export function startWorkers(context: BotContext): Worker[] {
|
||||
logger.error({ jobId: job?.id, error }, 'Guild backup restore job failed');
|
||||
});
|
||||
|
||||
const suggestionsWorker = new Worker<SuggestionStatusUpdateJob>(
|
||||
suggestionsQueueName,
|
||||
async (job) => {
|
||||
if (job.name !== 'suggestionStatusUpdate') {
|
||||
return;
|
||||
}
|
||||
return runSuggestionStatusUpdateJob(context, job.data);
|
||||
},
|
||||
{ connection: redis }
|
||||
);
|
||||
suggestionsWorker.on('failed', (job, error) => {
|
||||
logger.error({ jobId: job?.id, error }, 'Suggestion status update job failed');
|
||||
});
|
||||
|
||||
return [
|
||||
moderationWorker,
|
||||
backupWorker,
|
||||
@@ -293,7 +316,8 @@ export function startWorkers(context: BotContext): Worker[] {
|
||||
statsWorker,
|
||||
feedsWorker,
|
||||
scheduleWorker,
|
||||
guildBackupWorker
|
||||
guildBackupWorker,
|
||||
suggestionsWorker
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export { suggestionsCommands } from './commands.js';
|
||||
export { isSuggestionButton, handleSuggestionButton } from './buttons.js';
|
||||
export { runSuggestionStatusUpdateJob } from './service.js';
|
||||
|
||||
@@ -10,6 +10,7 @@ import { SuggestionStatusSchema, t, tf, type SuggestionStatus } from '@nexumi/sh
|
||||
import type { Locale } from '@nexumi/shared';
|
||||
import { ensureGuild } from '../../guild.js';
|
||||
import { logger } from '../../logger.js';
|
||||
import { getGuildLocale } from '../../i18n.js';
|
||||
import type { BotContext } from '../../types.js';
|
||||
|
||||
export const SUGGESTION_VOTE_PREFIX = 'sug:vote:';
|
||||
@@ -339,3 +340,24 @@ export async function updateSuggestionStatus(
|
||||
await notifyAuthor(context, updated, locale, params.status, params.reason);
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for the `suggestionStatusUpdate` BullMQ job, enqueued by the
|
||||
* WebUI dashboard (which has no discord.js Client to move/edit the
|
||||
* suggestion embed or DM the author). Resolves the guild's locale and
|
||||
* delegates to {@link updateSuggestionStatus} so staff actions performed
|
||||
* from the dashboard behave identically to `/suggestion approve|deny|...`.
|
||||
*/
|
||||
export async function runSuggestionStatusUpdateJob(
|
||||
context: BotContext,
|
||||
params: {
|
||||
suggestionId: string;
|
||||
guildId: string;
|
||||
status: SuggestionStatus;
|
||||
reason: string;
|
||||
}
|
||||
): Promise<{ id: string }> {
|
||||
const locale = await getGuildLocale(context.prisma, params.guildId);
|
||||
const updated = await updateSuggestionStatus(context, params, locale);
|
||||
return { id: updated.id };
|
||||
}
|
||||
|
||||
@@ -25,3 +25,5 @@ export const scheduleQueueName = 'schedules';
|
||||
export const scheduleQueue = new Queue(scheduleQueueName, { connection: redis });
|
||||
export const guildBackupQueueName = 'guild-backups';
|
||||
export const guildBackupQueue = new Queue(guildBackupQueueName, { connection: redis });
|
||||
export const suggestionsQueueName = 'suggestions';
|
||||
export const suggestionsQueue = new Queue(suggestionsQueueName, { connection: redis });
|
||||
|
||||
Reference in New Issue
Block a user