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 1/3] 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")}` ] From 37a023dc9b8ba4e4e9273ca513a2041046d484b2 Mon Sep 17 00:00:00 2001 From: big nutty <3515180-bignutty@users.noreply.gitlab.com> Date: Tue, 6 Aug 2024 23:37:45 +0000 Subject: [PATCH 2/3] fix comma --- commands/message/core/stats.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/message/core/stats.js b/commands/message/core/stats.js index 52db8b3..86a4152 100644 --- a/commands/message/core/stats.js +++ b/commands/message/core/stats.js @@ -78,9 +78,9 @@ module.exports = { if(applicationMetadata?.body?.approximate_user_install_count) display.push( `${iconPill("user", "Installations")} ${highlight(` ${applicationMetadata?.body?.approximate_user_install_count} `)}` ) - + display = [ - ...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())} `)}`, From b4e48f1f21e79c6c96c462c6cb6626eb6f1e6c52 Mon Sep 17 00:00:00 2001 From: big nutty <3515180-bignutty@users.noreply.gitlab.com> Date: Tue, 6 Aug 2024 23:40:31 +0000 Subject: [PATCH 3/3] guh --- commands/message/core/stats.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/commands/message/core/stats.js b/commands/message/core/stats.js index 86a4152..761271a 100644 --- a/commands/message/core/stats.js +++ b/commands/message/core/stats.js @@ -75,18 +75,14 @@ module.exports = { `${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} `)}` - ) + 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")}` - ] + display.push(`${iconPill("robot", "Shard ")} ${highlight(` ${context.shardId + 1}/${context.manager.cluster.shardCount} `)}`) + display.push(`${iconPill("latency", "Memory Usage ")} ${highlight(` ${Math.round(formatted.usage / 1024 / 1024)}MB `)}`) + display.push(`${iconPill("clock", "Uptime ")} ${highlight(` ${format(process.uptime())} `)}`) + display.push(``) + display.push(`${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")}`) return editOrReply(context, createEmbed("default", context, { description: display.join('\n')