refactor: replace direct EmbedBuilder usage with a new createBaseEmbed helper for consistent embed creation

This commit is contained in:
syntaxbullet
2025-12-24 11:17:59 +01:00
parent 1189483244
commit eaf97572a4
14 changed files with 58 additions and 79 deletions

View File

@@ -1,6 +1,7 @@
import { createCommand } from "@/lib/utils";
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
import { SlashCommandBuilder } from "discord.js";
import { userService } from "@/modules/user/user.service";
import { createBaseEmbed } from "@lib/embeds";
export const balance = createCommand({
data: new SlashCommandBuilder()
@@ -22,10 +23,8 @@ export const balance = createCommand({
const user = await userService.getOrCreateUser(targetUser.id, targetUser.username);
const embed = new EmbedBuilder()
.setAuthor({ name: targetUser.username, iconURL: targetUser.displayAvatarURL() })
.setDescription(`**Balance**: ${user.balance || 0n} AU`)
.setColor("Yellow");
const embed = createBaseEmbed(undefined, `**Balance**: ${user.balance || 0n} AU`, "Yellow")
.setAuthor({ name: targetUser.username, iconURL: targetUser.displayAvatarURL() });
await interaction.editReply({ embeds: [embed] });
}

View File

@@ -1,8 +1,8 @@
import { createCommand } from "@/lib/utils";
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
import { SlashCommandBuilder } from "discord.js";
import { economyService } from "@/modules/economy/economy.service";
import { createErrorEmbed } from "@lib/embeds";
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
import { UserError } from "@/lib/errors";
export const daily = createCommand({
@@ -13,16 +13,13 @@ export const daily = createCommand({
try {
const result = await economyService.claimDaily(interaction.user.id);
const embed = new EmbedBuilder()
.setTitle("💰 Daily Reward Claimed!")
.setDescription(`You claimed ** ${result.amount}** Astral Units!${result.isWeekly ? `\n🎉 **Weekly Bonus!** +${result.weeklyBonus} extra!` : ''}`)
const embed = createSuccessEmbed(`You claimed ** ${result.amount}** Astral Units!${result.isWeekly ? `\n🎉 **Weekly Bonus!** +${result.weeklyBonus} extra!` : ''}`, "💰 Daily Reward Claimed!")
.addFields(
{ name: "Streak", value: `🔥 ${result.streak} days`, inline: true },
{ name: "Weekly Progress", value: `${"🟩".repeat(result.streak % 7 || 7)}${"⬜".repeat(7 - (result.streak % 7 || 7))} (${result.streak % 7 || 7}/7)`, inline: true },
{ name: "Next Reward", value: `<t:${Math.floor(result.nextReadyAt.getTime() / 1000)}:R> `, inline: true }
)
.setColor("Gold")
.setTimestamp();
.setColor("Gold");
await interaction.reply({ embeds: [embed] });

View File

@@ -1,10 +1,10 @@
import { createCommand } from "@/lib/utils";
import { SlashCommandBuilder, EmbedBuilder, MessageFlags } from "discord.js";
import { SlashCommandBuilder, MessageFlags } from "discord.js";
import { economyService } from "@/modules/economy/economy.service";
import { userService } from "@/modules/user/user.service";
import { config } from "@/lib/config";
import { createErrorEmbed } from "@lib/embeds";
import { createErrorEmbed, createSuccessEmbed } from "@lib/embeds";
import { UserError } from "@/lib/errors";
export const pay = createCommand({
@@ -49,12 +49,7 @@ export const pay = createCommand({
await interaction.deferReply();
await economyService.transfer(senderId, receiverId, amount);
const embed = new EmbedBuilder()
.setTitle("💸 Transfer Successful")
.setDescription(`Successfully sent ** ${amount}** Astral Units to <@${targetUser.id}>.`)
.setColor("Green")
.setTimestamp();
const embed = createSuccessEmbed(`Successfully sent ** ${amount}** Astral Units to <@${targetUser.id}>.`, "💸 Transfer Successful");
await interaction.editReply({ embeds: [embed], content: `<@${receiverId}>` });
} catch (error: any) {

View File

@@ -1,7 +1,7 @@
import { createCommand } from "@/lib/utils";
import { SlashCommandBuilder, EmbedBuilder, ChannelType, ActionRowBuilder, ButtonBuilder, ButtonStyle, ThreadAutoArchiveDuration, MessageFlags } from "discord.js";
import { SlashCommandBuilder, ChannelType, ActionRowBuilder, ButtonBuilder, ButtonStyle, ThreadAutoArchiveDuration, MessageFlags } from "discord.js";
import { TradeService } from "@/modules/trade/trade.service";
import { createErrorEmbed, createWarningEmbed } from "@lib/embeds";
import { createErrorEmbed, createWarningEmbed, createBaseEmbed } from "@lib/embeds";
export const trade = createCommand({
data: new SlashCommandBuilder()
@@ -64,10 +64,7 @@ export const trade = createCommand({
);
// Send Dashboard to Thread
const embed = new EmbedBuilder()
.setTitle("🤝 Trading Session")
.setDescription(`Trade started between ${interaction.user} and ${targetUser}.\nUse the controls below to build your offer.`)
.setColor(0xFFD700)
const embed = createBaseEmbed("🤝 Trading Session", `Trade started between ${interaction.user} and ${targetUser}.\nUse the controls below to build your offer.`, 0xFFD700)
.addFields(
{ name: interaction.user.username, value: "*Empty Offer*", inline: true },
{ name: targetUser.username, value: "*Empty Offer*", inline: true }