feat: add icone command
This commit is contained in:
62
src/index.ts
62
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);
|
||||
|
||||
38
src/wov.ts
38
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user