feat: add icone command

This commit is contained in:
Pihkaal
2025-08-18 23:19:59 +02:00
parent 52b87e740d
commit bbb4472083
2 changed files with 100 additions and 0 deletions

View File

@@ -4,8 +4,10 @@ import { makeResultEmbed } from "./discord";
import { env } from "./env"; import { env } from "./env";
import { import {
checkForNewQuest, checkForNewQuest,
getClanInfos,
getClanMembers, getClanMembers,
getLatestQuest, getLatestQuest,
searchPlayer,
type QuestResult, type QuestResult,
} from "./wov"; } from "./wov";
@@ -156,6 +158,66 @@ client.on("messageCreate", async (message) => {
.split(" "); .split(" ");
if (command === "ping") { if (command === "ping") {
await message.reply("pong"); 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") { } else if (command === "result") {
const quest = await getLatestQuest(); const quest = await getLatestQuest();
await askForGrinders(quest); await askForGrinders(quest);

View File

@@ -77,3 +77,41 @@ export const getClanMembers = async (): Promise<
await cacheFile.write(JSON.stringify({ timestamp: Date.now(), data })); await cacheFile.write(JSON.stringify({ timestamp: Date.now(), data }));
return 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;
};