From 7f99765d20025aa114a8f0ec62f719eb55e3fcc0 Mon Sep 17 00:00:00 2001 From: targeteater <141521527+targeteater@users.noreply.github.com> Date: Fri, 18 Oct 2024 19:58:24 +0200 Subject: [PATCH] Update autorotate.js --- structs/autorotate.js | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/structs/autorotate.js b/structs/autorotate.js index 9eefaee..535790d 100644 --- a/structs/autorotate.js +++ b/structs/autorotate.js @@ -322,6 +322,21 @@ function updatecfgomg(dailyItems, featuredItems) { log.AutoRotation("The item shop has rotated!"); } +async function fetchItemIcon(itemName) { + try { + const response = await axios.get(`https://fortnite-api.com/v2/cosmetics/br/search?name=${encodeURIComponent(itemName)}`); + if (response.data && response.data.data && response.data.data.images && response.data.data.images.smallIcon) { + return response.data.data.images.smallIcon; + } else { + log.error(`No small icon found for ${itemName}`); + return null; + } + } catch (error) { + log.error(`Error fetching icon for ${itemName}:`, error.message || error); + return null; + } +} + async function discordpost(itemShop) { const embeds = []; @@ -329,17 +344,18 @@ async function discordpost(itemShop) { return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); } - function formatItemEmbed(item, authorTitle = null) { + async function formatItemEmbed(item, authorTitle = null) { const itemName = `**${capitalizeFirstLetter(item.name || "Unknown Item")}**`; const itemRarity = `Rarity: **${capitalizeFirstLetter(item.rarity?.displayValue || "Unknown")}**`; const itemPrice = `Price: **${notproperpricegen(item)} V-Bucks**`; + const itemIcon = await fetchItemIcon(item.name); const embed = { title: itemName, color: 0x00FF7F, description: `${itemRarity}\n${itemPrice}`, thumbnail: { - url: item.images?.icon || "https://i.imgur.com/2RImwlb.png" + url: itemIcon || 'https://via.placeholder.com/150' // prevents yk from crashing and fake images } }; @@ -368,24 +384,21 @@ async function discordpost(itemShop) { title: "Reload Item Shop", description: `These are the cosmetics for today!`, color: 0x00FF7F, - thumbnail: { - url: "https://i.imgur.com/2RImwlb.png" - }, fields: [], }); if (itemShop.featured.length > 0) { - itemShop.featured.forEach((item, index) => { - const embed = formatItemEmbed(item, index === 0 ? "Feature Item" : null); + for (const [index, item] of itemShop.featured.entries()) { + const embed = await formatItemEmbed(item, index === 0 ? "Feature Item" : null); embeds.push(embed); - }); + } } if (itemShop.daily.length > 0) { - itemShop.daily.forEach((item, index) => { - const embed = formatItemEmbed(item, index === 0 ? "Daily Item" : null); + for (const [index, item] of itemShop.daily.entries()) { + const embed = await formatItemEmbed(item, index === 0 ? "Daily Item" : null); embeds.push(embed); - }); + } } const nextRotationTimestamp = getNextRotationTime(); @@ -407,7 +420,7 @@ async function rotateshop() { try { const cosmetics = await fetchitems(); if (cosmetics.length === 0) { - log.error('No cosmetics found?'); + log.error('No cosmetics found?'); // target was here! return; } @@ -450,4 +463,4 @@ function milisecstillnextrotation() { return millisUntilNextRotation; } -setTimeout(rotateshop, milisecstillnextrotation()); \ No newline at end of file +setTimeout(rotateshop, milisecstillnextrotation());