From e4d498d26dd7268623512c0224f28c8c985dd179 Mon Sep 17 00:00:00 2001 From: binary-blazer Date: Wed, 22 Nov 2023 20:03:35 +0100 Subject: [PATCH] =?UTF-8?q?[=E2=9C=85]=20real=20stats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - now the list checks for the real server count of the bot if it is available in the discord api from japi. If not it still uses the topgg api. --- cmd/check.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/cmd/check.js b/cmd/check.js index c7a69b4..aed8b0d 100644 --- a/cmd/check.js +++ b/cmd/check.js @@ -6,6 +6,7 @@ dotenv.config(); const API_TOKEN = process.env.TOP_GG_TOKEN; const API_URL = "https://top.gg/api/bots?sort=server_count&limit=20"; +const JAPI_URL = "https://japi.rest/discord/v1/application/"; const headers = { Authorization: API_TOKEN, @@ -19,8 +20,35 @@ function formatCount(count) { await axios .get(API_URL, { headers: headers }) - .then((response) => { - const bots = response.data.results; + .then(async (response) => { + const _bots = response.data.results; + + let bots = []; + + for (let bot of _bots) { + await axios + .get(`${JAPI_URL}${bot.id}`) + .then((response) => { + const _bot = response.data.data.bot; + + bots.push({ + id: _bot?.id ?? bot.id, + username: _bot?.username ?? bot.username, + discriminator: _bot?.discriminator ?? bot.discriminator, + server_count: _bot?.approximate_guild_count ?? bot.server_count, + invite: bot.invite ?? `https://discord.com/oauth2/authorize?client_id=${bot.id}&scope=bot&permissions=0`, + }); + + if (bots.length === _bots.length) { + return; + } + }) + .catch((error) => { + console.log(error); + }); + } + + bots.sort((a, b) => b.server_count - a.server_count); let maxNameLength = Math.max( "Bot".length, @@ -62,4 +90,4 @@ await axios }) .catch((error) => { console.log(error); - }); + }); \ No newline at end of file