mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 22:23:03 -04:00
remove analytics, update stats command
This commit is contained in:
parent
72789e644f
commit
a24cbf5a36
4 changed files with 55 additions and 106 deletions
|
@ -1,15 +1,26 @@
|
|||
const { codeblock } = require('../../../labscore/utils/markdown')
|
||||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { highlight, iconPill } = require('../../../labscore/utils/markdown')
|
||||
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||
|
||||
const { paginator } = require('../../../labscore/client');
|
||||
const { editOrReply } = require('../../../labscore/utils/message');
|
||||
const { getCommandStatistics } = require('../../../labscore/analytics');
|
||||
|
||||
function format(seconds){
|
||||
function pad(s){
|
||||
return (s < 10 ? '0' : '') + s;
|
||||
}
|
||||
var hours = Math.floor(seconds / (60*60));
|
||||
var minutes = Math.floor(seconds % (60*60) / 60);
|
||||
var seconds = Math.floor(seconds % 60);
|
||||
|
||||
if(hours == 0) return pad(minutes) + ' Minutes, ' + pad(seconds) + ' Seconds'
|
||||
return pad(hours) + ' Hours, ' + pad(minutes) + ' Minutes, ' + pad(seconds) + ' Seconds'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'stats',
|
||||
aliases: ['usage', 'uptime'],
|
||||
metadata: {
|
||||
description: 'Lists command usage statistics.',
|
||||
description_short: 'Shows command usage stats.',
|
||||
description: 'Shows statistics about the bot.',
|
||||
description_short: 'Shows bot stats.',
|
||||
examples: ['stats'],
|
||||
category: 'core',
|
||||
usage: 'stats'
|
||||
|
@ -17,39 +28,51 @@ module.exports = {
|
|||
run: async (context) => {
|
||||
context.triggerTyping();
|
||||
try{
|
||||
let stats = await getCommandStatistics();
|
||||
|
||||
let pages = [];
|
||||
let ranking = 1;
|
||||
|
||||
for (var i = 0; i < Object.keys(stats).length; i += 20) {
|
||||
list = []
|
||||
if(pages.length == 0){list.push(` | Total - ${Object.values(stats).reduce((a, b) => a + b, 0)}`)}
|
||||
|
||||
Object.keys(stats).forEach(function(elem){
|
||||
dispnum = `${ranking}`
|
||||
if(`${ranking}`.length == 1){dispnum = ` ${ranking}`}
|
||||
list.push(`${dispnum} | ${elem} - ${stats[elem]}`)
|
||||
ranking++
|
||||
if(context.manager){
|
||||
const globalStats = await context.manager.broadcastEval((cluster) => {
|
||||
const shardUsage = process.memoryUsage();
|
||||
|
||||
let stats = {
|
||||
usage: shardUsage.heapTotal + shardUsage.external + shardUsage.arrayBuffers,
|
||||
guilds: 0
|
||||
}
|
||||
for (const [shardId, shard] of cluster.shards) {
|
||||
stats.guilds += shard.guilds.length;
|
||||
}
|
||||
return stats
|
||||
})
|
||||
|
||||
pages.push({embeds:[
|
||||
createEmbed("default", context, {
|
||||
description: codeblock("autohotkey", list)
|
||||
})
|
||||
]})
|
||||
let formatted = {
|
||||
guilds: 0,
|
||||
usage: 0
|
||||
}
|
||||
|
||||
for (let cid in globalStats) {
|
||||
const cstats = globalStats[cid];
|
||||
formatted.guilds += cstats.guilds
|
||||
formatted.usage += cstats.usage
|
||||
}
|
||||
|
||||
const display = [
|
||||
`${iconPill("house", "Servers ")} ${highlight(` ${formatted.guilds} `)}`,
|
||||
`${iconPill("robot", "Shard ")} ${highlight(` ${context.shardId + 1}/${context.manager.cluster.shardCount} `)}`,
|
||||
`${iconPill("connection", "Memory Usage")} ${highlight(` ${Math.round(formatted.usage / 1024 / 1024)}MB `)}`,
|
||||
`${iconPill("timer", "Uptime ")} ${highlight(` ${format(process.uptime())} `)}`
|
||||
]
|
||||
|
||||
return editOrReply(context, createEmbed("default", context, {
|
||||
//description: codeblock("autohotkey", [`Guilds: ${formatted.guilds}`, `Shard: ${context.shardId + 1}/${context.manager.cluster.shardCount}`, `Memory Usage: ${Math.round(formatted.usage / 1024 / 1024)}MB`])
|
||||
description: display.join('\n')
|
||||
}))
|
||||
|
||||
} else {
|
||||
return editOrReply(context, createEmbed("error", context, "Bot is not running in cluster mode."))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
});
|
||||
|
||||
return;
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds: [createEmbed("error", context, "Unable to fetch command statistics.")]})
|
||||
return editOrReply(context, {embeds: [createEmbed("error", context, "Unable to fetch bot statistics.")]})
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue