Refactor embed handling and enhance user experience across components
- Integrated the new `buildEmbedFromPayload` function in Scheduler, Tags, and Welcome components to streamline embed creation and management. - Updated validation schemas to require embed content checks, ensuring robust data integrity for embeds. - Enhanced localization files to include new placeholder descriptions and improve user guidance for embed fields. - Refactored embed parsing logic to utilize the `WelcomeEmbedSchema`, improving consistency and validation across the application.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
EmbedBuilder,
|
||||
PermissionFlagsBits,
|
||||
type GuildTextBasedChannel,
|
||||
type MessageCreateOptions,
|
||||
@@ -8,6 +7,7 @@ import {
|
||||
import { WelcomeEmbedSchema, expandBracketChannelMentions, t, tf } from '@nexumi/shared';
|
||||
import type { ScheduledMessage } from '@prisma/client';
|
||||
import { ensureGuild } from '../../guild.js';
|
||||
import { buildEmbedFromPayload } from '../../lib/embed-payload.js';
|
||||
import { logger } from '../../logger.js';
|
||||
import { scheduleQueue } from '../../queues.js';
|
||||
import type { BotContext } from '../../types.js';
|
||||
@@ -94,18 +94,9 @@ export function buildAnnouncementPayload(schedule: {
|
||||
rolePingId: string | null;
|
||||
}): MessageCreateOptions {
|
||||
const embedData = parseStoredEmbed(schedule.embed);
|
||||
const embeds: EmbedBuilder[] = [];
|
||||
|
||||
if (embedData) {
|
||||
const embed = new EmbedBuilder().setColor(embedData.color ?? 0x6366f1);
|
||||
if (embedData.title) {
|
||||
embed.setTitle(expandBracketChannelMentions(embedData.title));
|
||||
}
|
||||
if (embedData.description) {
|
||||
embed.setDescription(expandBracketChannelMentions(embedData.description));
|
||||
}
|
||||
embeds.push(embed);
|
||||
}
|
||||
const embed = buildEmbedFromPayload(embedData, {
|
||||
renderText: expandBracketChannelMentions
|
||||
});
|
||||
|
||||
const baseContent = expandBracketChannelMentions(schedule.content?.trim() ?? '');
|
||||
const roleMention = schedule.rolePingId ? `<@&${schedule.rolePingId}>` : '';
|
||||
@@ -115,8 +106,8 @@ export function buildAnnouncementPayload(schedule: {
|
||||
if (content) {
|
||||
payload.content = content;
|
||||
}
|
||||
if (embeds.length > 0) {
|
||||
payload.embeds = embeds;
|
||||
if (embed) {
|
||||
payload.embeds = [embed];
|
||||
}
|
||||
if (schedule.rolePingId) {
|
||||
payload.allowedMentions = { roles: [schedule.rolePingId] };
|
||||
|
||||
Reference in New Issue
Block a user