From bbb44720836a3a80c047554788d0224009f030f7 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Mon, 18 Aug 2025 23:19:59 +0200 Subject: [PATCH] feat: add icone command --- src/index.ts | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/wov.ts | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/index.ts b/src/index.ts index 0ec712c..c71b4af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,10 @@ import { makeResultEmbed } from "./discord"; import { env } from "./env"; import { checkForNewQuest, + getClanInfos, getClanMembers, getLatestQuest, + searchPlayer, type QuestResult, } from "./wov"; @@ -156,6 +158,66 @@ client.on("messageCreate", async (message) => { .split(" "); if (command === "ping") { await message.reply("pong"); + } else if (command === "icone") { + let playerName = args[0]; + if (!playerName) { + await message.reply({ + embeds: [ + { + description: `### ❌ Erreur\n\n\n\nUsage:\`@LBF icone NOM_JOUEUR\`, exemple: \`@LBF icone Yuno\`.\n**Attention les majuscules sont importantes**`, + color: 15335424, + }, + ], + }); + return; + } + + const player = await searchPlayer(playerName); + if (!player) { + await message.reply({ + embeds: [ + { + description: `### ❌ Erreur\n\n\n\nJoueur·euse non trouvé·e.\n**Attention les majuscules sont importantes**`, + color: 15335424, + }, + ], + }); + return; + } + + if (!player.clanId) { + await message.reply({ + embeds: [ + { + description: `### ❌ Erreur\n\n\n\nCette personne n'a pas de clan.\n**Attention les majuscules sont importantes**`, + color: 15335424, + }, + ], + }); + return; + } + + const clan = await getClanInfos(player.clanId); + if (!clan) { + await message.reply({ + embeds: [ + { + description: `### ❌ Erreur\n\n\n\nImpossible de récupérer les informations du clan.`, + color: 15335424, + }, + ], + }); + return; + } + + await message.reply({ + embeds: [ + { + description: `### ✅ Informations du clan\n\n**Nom:** \`\`\`${clan.name}\`\`\`\n**Tag:** \`\`\`${clan.tag}\`\`\``, + color: 65280, + }, + ], + }); } else if (command === "result") { const quest = await getLatestQuest(); await askForGrinders(quest); diff --git a/src/wov.ts b/src/wov.ts index 8b6a949..76834ce 100644 --- a/src/wov.ts +++ b/src/wov.ts @@ -77,3 +77,41 @@ export const getClanMembers = async (): Promise< await cacheFile.write(JSON.stringify({ timestamp: Date.now(), data })); return data; }; + +export const searchPlayer = async (username: string) => { + try { + const response = await fetch( + `https://api.wolvesville.com//players/search?username=${username}`, + { + method: "GET", + headers: { Authorization: `Bot ${env.WOV_API_KEY}` }, + }, + ); + + if (response.status === 404) return null; + + const data = (await response.json()) as { + clanId: string | null; + }; + + return data; + } catch { + return null; + } +}; + +export const getClanInfos = async (clanId: string) => { + const response = await fetch( + `https://api.wolvesville.com/clans/${clanId}/info`, + { + method: "GET", + headers: { Authorization: `Bot ${env.WOV_API_KEY}` }, + }, + ); + const data = (await response.json()) as { + name: string; + tag: string; + }; + + return data; +};