refactor: replace direct EmbedBuilder usage with a new createBaseEmbed helper for consistent embed creation
This commit is contained in:
@@ -2,7 +2,6 @@ import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
EmbedBuilder,
|
||||
ModalBuilder,
|
||||
StringSelectMenuBuilder,
|
||||
TextInputBuilder,
|
||||
@@ -13,6 +12,7 @@ import {
|
||||
import { items } from "@/db/schema";
|
||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
||||
import type { ItemUsageData, ItemEffect } from "@/lib/types";
|
||||
import { createBaseEmbed } from "@lib/embeds";
|
||||
|
||||
// --- Types ---
|
||||
export interface DraftItem {
|
||||
@@ -66,9 +66,7 @@ export const renderWizard = (userId: string, isDraft = true) => {
|
||||
draftSession.set(userId, draft);
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`🛠️ Item Creator: ${draft.name}`)
|
||||
.setColor("Blue")
|
||||
const embed = createBaseEmbed(`🛠️ Item Creator: ${draft.name}`, undefined, "Blue")
|
||||
.addFields(
|
||||
{ name: "General", value: `**Type:** ${draft.type}\n**Rarity:** ${draft.rarity}\n**Desc:** ${draft.description}`, inline: true },
|
||||
{ name: "Economy", value: `**Price:** ${draft.price ? `${draft.price} 🪙` : "Not for sale"}`, inline: true },
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, EmbedBuilder, ButtonStyle } from "discord.js";
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle } from "discord.js";
|
||||
import { lootdropService } from "./lootdrop.service";
|
||||
import { createErrorEmbed } from "@/lib/embeds";
|
||||
import { createErrorEmbed, createSuccessEmbed, createBaseEmbed } from "@/lib/embeds";
|
||||
|
||||
export async function handleLootdropInteraction(interaction: ButtonInteraction) {
|
||||
if (interaction.customId === "lootdrop_claim") {
|
||||
@@ -17,9 +17,7 @@ export async function handleLootdropInteraction(interaction: ButtonInteraction)
|
||||
const originalEmbed = interaction.message.embeds[0];
|
||||
if (!originalEmbed) return;
|
||||
|
||||
const newEmbed = new EmbedBuilder(originalEmbed.data)
|
||||
.setDescription(`✅ Claimed by <@${interaction.user.id}> for **${result.amount} ${result.currency}**!`)
|
||||
.setColor("#00FF00");
|
||||
const newEmbed = createBaseEmbed(originalEmbed.title || "💰 LOOTDROP!", `✅ Claimed by <@${interaction.user.id}> for **${result.amount} ${result.currency}**!`, "#00FF00");
|
||||
|
||||
// Disable button
|
||||
// We reconstruct the button using builders for safety
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { Message, TextChannel, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } from "discord.js";
|
||||
import { config } from "@/lib/config";
|
||||
import { economyService } from "./economy.service";
|
||||
import { createBaseEmbed } from "@lib/embeds";
|
||||
|
||||
import { lootdrops } from "@/db/schema";
|
||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
||||
@@ -91,11 +92,7 @@ class LootdropService {
|
||||
const reward = Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
const currency = config.lootdrop.reward.currency;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("💰 LOOTDROP!")
|
||||
.setDescription(`A lootdrop has appeared! Click the button below to claim **${reward} ${currency}**!`)
|
||||
.setColor("#FFD700")
|
||||
.setTimestamp();
|
||||
const embed = createBaseEmbed("💰 LOOTDROP!", `A lootdrop has appeared! Click the button below to claim **${reward} ${currency}**!`, "#FFD700");
|
||||
|
||||
const claimButton = new ButtonBuilder()
|
||||
.setCustomId("lootdrop_claim")
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
ModalSubmitInteraction,
|
||||
StringSelectMenuInteraction,
|
||||
type Interaction,
|
||||
EmbedBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
@@ -13,10 +12,11 @@ import {
|
||||
TextInputStyle,
|
||||
ThreadChannel,
|
||||
TextChannel,
|
||||
EmbedBuilder
|
||||
} from "discord.js";
|
||||
import { TradeService } from "./trade.service";
|
||||
import { inventoryService } from "@/modules/inventory/inventory.service";
|
||||
import { createErrorEmbed, createWarningEmbed, createSuccessEmbed, createInfoEmbed } from "@lib/embeds";
|
||||
import { createErrorEmbed, createWarningEmbed, createSuccessEmbed, createInfoEmbed, createBaseEmbed } from "@lib/embeds";
|
||||
|
||||
const EMBED_COLOR = 0xFFD700; // Gold
|
||||
|
||||
@@ -207,9 +207,7 @@ export async function updateTradeDashboard(interaction: Interaction, threadId: s
|
||||
// Execute Trade
|
||||
try {
|
||||
await TradeService.executeTrade(threadId);
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("✅ Trade Completed")
|
||||
.setColor("Green")
|
||||
const embed = createBaseEmbed("✅ Trade Completed", undefined, "Green")
|
||||
.addFields(
|
||||
{ name: session.userA.username, value: formatOffer(session.userA), inline: true },
|
||||
{ name: session.userB.username, value: formatOffer(session.userB), inline: true }
|
||||
@@ -246,9 +244,7 @@ export async function updateTradeDashboard(interaction: Interaction, threadId: s
|
||||
}
|
||||
|
||||
// Build Status Embed
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("🤝 Trading Session")
|
||||
.setColor(EMBED_COLOR)
|
||||
const embed = createBaseEmbed("🤝 Trading Session", undefined, EMBED_COLOR)
|
||||
.addFields(
|
||||
{
|
||||
name: `${session.userA.username} ${session.userA.locked ? '✅ (Ready)' : '✏️ (Editing)'}`,
|
||||
|
||||
Reference in New Issue
Block a user