From 775edf520271f9e5c8ac9eb6d06972e5730a66b7 Mon Sep 17 00:00:00 2001 From: big nutty <3515180-bignutty@users.noreply.gitlab.com> Date: Tue, 6 Aug 2024 23:36:34 +0000 Subject: [PATCH] add approx install count --- commands/message/core/stats.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/commands/message/core/stats.js b/commands/message/core/stats.js index 88ac491..52db8b3 100644 --- a/commands/message/core/stats.js +++ b/commands/message/core/stats.js @@ -7,6 +7,8 @@ const { editOrReply } = require('#utils/message'); // TODO: Turn this into a general purpose permissions constant const { Permissions } = require("detritus-client/lib/constants"); +const superagent = require("superagent"); + // TODO: Move this into utils function format(seconds){ function pad(s){ @@ -61,11 +63,27 @@ module.exports = { formatted.usage += cstats.usage } + let applicationMetadata; + try{ + applicationMetadata = await superagent.get(`https://canary.discord.com/api/v9/applications/${context.client.user.id}`) + .set({ + "Authorization": "Bot " + context.client.token + }) + }catch(e){} + const display = [ - `${iconPill("home", "Servers ")} ${highlight(` ${formatted.guilds} `)}`, - `${iconPill("robot", "Shard ")} ${highlight(` ${context.shardId + 1}/${context.manager.cluster.shardCount} `)}`, - `${iconPill("latency", "Memory Usage")} ${highlight(` ${Math.round(formatted.usage / 1024 / 1024)}MB `)}`, - `${iconPill("clock", "Uptime ")} ${highlight(` ${format(process.uptime())} `)}`, + `${iconPill("home", "Servers ")} ${highlight(` ${formatted.guilds} `)}` + ] + + if(applicationMetadata?.body?.approximate_user_install_count) display.push( + `${iconPill("user", "Installations")} ${highlight(` ${applicationMetadata?.body?.approximate_user_install_count} `)}` + ) + + display = [ + ...display + `${iconPill("robot", "Shard ")} ${highlight(` ${context.shardId + 1}/${context.manager.cluster.shardCount} `)}`, + `${iconPill("latency", "Memory Usage ")} ${highlight(` ${Math.round(formatted.usage / 1024 / 1024)}MB `)}`, + `${iconPill("clock", "Uptime ")} ${highlight(` ${format(process.uptime())} `)}`, ``, `${iconLinkPill('gitlab', OPEN_SOURCE_REPOSITORY_URL, 'Source Code')} ​ ​ ${iconLinkPill('link', context.application.oauth2UrlFormat({ scope: 'bot applications.commands', permissions: 412317248576 }), `Invite ${context.client.user.username}`).replace("ptb.discordapp.com","discord.com")}` ]