refactor(discord-bot): improve 'icone' command

This commit is contained in:
Pihkaal
2025-12-05 17:13:49 +01:00
parent 19cb5b445b
commit d82c6589c6

View File

@@ -1,51 +1,51 @@
import { EmbedBuilder } from "discord.js";
import type { Command } from "~/commands"; import type { Command } from "~/commands";
import { searchPlayer, getClanInfos } from "~/services/wov"; import { searchPlayer, getClanInfos } from "~/services/wov";
import { createErrorEmbed } from "~/utils/discord"; import { replyError } from "~/utils/discord";
export const iconeCommand: Command = async (message, args) => { export const iconeCommand: Command = async (message, args) => {
let playerName = args[0]; const playerName = args[0];
if (!playerName) { if (!playerName) {
await message.reply( await replyError(
createErrorEmbed( message,
"Usage:`@LBF icone NOM_JOUEUR`, exemple: `@LBF icone Yuno`.\n**Attention les majuscules sont importantes**", "Usage:`@LBF icone NOM_JOUEUR`, exemple: `@LBF icone Yuno`.\n**Attention les majuscules sont importantes**",
),
); );
return; return;
} }
const player = await searchPlayer(playerName); const player = await searchPlayer(playerName);
if (!player) { if (!player) {
await message.reply( await replyError(
createErrorEmbed( message,
"Joueur·euse non trouvé·e.\n**Attention les majuscules sont importantes**", "Joueur·euse non trouvé·e.\n**Attention les majuscules sont importantes**",
),
); );
return; return;
} }
if (!player.clanId) { if (!player.clanId) {
await message.reply( await replyError(
createErrorEmbed( message,
"Cette personne __n'a pas de clan__ ou __a caché son clan__.\n**Attention les majuscules sont importantes**", "Cette personne __n'a pas de clan__ ou __a caché son clan__.\n**Attention les majuscules sont importantes**",
),
); );
return; return;
} }
const clan = await getClanInfos(player.clanId); const clan = await getClanInfos(player.clanId);
if (!clan) { if (!clan) {
await message.reply( await replyError(
createErrorEmbed("Impossible de récupérer les informations du clan."), message,
"Impossible de récupérer les informations du clan.",
); );
return; return;
} }
await message.reply({ await message.reply({
embeds: [ embeds: [
{ new EmbedBuilder()
description: `### ✅ Informations du clan\n\n**Nom:** \`\`\`${clan.name}\`\`\`\n**Tag:** \`\`\`${clan.tag}\`\`\``, .setDescription(
color: 65280, `### ✅ Informations du clan\n\n**Nom:** \`\`\`${clan.name}\`\`\`\n**Tag:** \`\`\`${clan.tag}\`\`\``,
}, )
.setColor(65280),
], ],
}); });
}; };