refactor: improve code quality
This commit is contained in:
@@ -1,57 +1,43 @@
|
||||
import { EmbedBuilder } from "discord.js";
|
||||
import type { Command } from "~/commands";
|
||||
import { searchPlayer, getClanInfos } from "~/services/wov";
|
||||
import { replyError } from "~/utils/discord";
|
||||
import { searchPlayer, getClanInfo } from "~/wov";
|
||||
import { replyError } from "~/discord";
|
||||
import type { Command } from "./index";
|
||||
import { noMention } from "~/discord";
|
||||
|
||||
export const iconeCommand: Command = async (message, args) => {
|
||||
const playerName = args[0];
|
||||
if (!playerName) {
|
||||
await replyError(
|
||||
message,
|
||||
"Usage:`@LBF icone NOM_JOUEUR`, exemple: `@LBF icone Yuno`.\n**Attention les majuscules sont importantes**",
|
||||
);
|
||||
return;
|
||||
}
|
||||
export const iconeCommand: Command = {
|
||||
help: "Affiche l'icone et le nom du clan d'un joueur",
|
||||
handler: async (message, args) => {
|
||||
const playerName = args[0];
|
||||
if (!playerName) {
|
||||
await replyError(message, "Usage:`@LBF icone NOM_JOUEUR`, exemple: `@LBF icone Yuno`.\n**Attention les majuscules sont importantes**");
|
||||
return;
|
||||
}
|
||||
|
||||
const player = await searchPlayer(playerName);
|
||||
if (!player) {
|
||||
await replyError(
|
||||
message,
|
||||
"Joueur·euse non trouvé·e.\n**Attention les majuscules sont importantes**",
|
||||
);
|
||||
return;
|
||||
}
|
||||
const player = await searchPlayer(playerName);
|
||||
if (!player) {
|
||||
await replyError(message, "Joueur·euse non trouvé·e.\n**Attention les majuscules sont importantes**");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.clanId) {
|
||||
await replyError(
|
||||
message,
|
||||
"Cette personne __n'a pas de clan__ ou __a caché son clan__.\n**Attention les majuscules sont importantes**",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!player.clanId) {
|
||||
await replyError(message, "Cette personne __n'a pas de clan__ ou __a caché son clan__.\n**Attention les majuscules sont importantes**");
|
||||
return;
|
||||
}
|
||||
|
||||
const clan = await getClanInfos(player.clanId);
|
||||
if (!clan) {
|
||||
await replyError(
|
||||
message,
|
||||
"Impossible de récupérer les informations du clan.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
const clan = await getClanInfo(player.clanId);
|
||||
if (!clan) {
|
||||
await replyError(message, "Impossible de récupérer les informations du clan.");
|
||||
return;
|
||||
}
|
||||
|
||||
await message.reply({
|
||||
content: clan.tag,
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`### ✅ Informations du clan\n\n**Nom:** \`\`\`${clan.name}\`\`\`\n**Tag:** \`\`\`${clan.tag}\`\`\``,
|
||||
)
|
||||
.setColor(65280),
|
||||
],
|
||||
options: {
|
||||
allowedMentions: {
|
||||
repliedUser: false,
|
||||
},
|
||||
await message.reply({
|
||||
options: noMention,
|
||||
content: clan.tag,
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(`### ✅ Informations du clan\n\n**Nom:** \`\`\`${clan.name}\`\`\`\n**Tag:** \`\`\`${clan.tag}\`\`\``)
|
||||
.setColor(65280)
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user