forked from Galactic/galactic-bot
109 lines
3.6 KiB
JavaScript
109 lines
3.6 KiB
JavaScript
const { Command } = require('../../../../interfaces/');
|
|
|
|
class StatsCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
name: 'about',
|
|
module: 'developer',
|
|
aliases: [
|
|
'stats',
|
|
'info'
|
|
],
|
|
usage: '',
|
|
restricted: true,
|
|
arguments: [
|
|
{
|
|
name: 'log',
|
|
type: 'BOOLEAN',
|
|
types: ['FLAG'],
|
|
description: 'Logs the output in the console.'
|
|
}
|
|
],
|
|
showUsage: false
|
|
});
|
|
|
|
}
|
|
|
|
async execute(message, { params, args }) {
|
|
|
|
// TODO:
|
|
// Add some stuff that only shows when a dev runs the command, for instance amount of cached messages etc
|
|
|
|
const { guild } = message;
|
|
const { shard } = this.client;
|
|
|
|
const evalFunc = (thisArg) => {
|
|
return {
|
|
users: thisArg.users.cache.size,
|
|
guilds: thisArg.guilds.cache.size,
|
|
channels: thisArg.channels.cache.size,
|
|
memory: Math.floor(process.memoryUsage().heapUsed / 1024 / 1024),
|
|
uptime: thisArg.uptime
|
|
};
|
|
};
|
|
|
|
const mEvalFunc = (thisArg) => {
|
|
return {
|
|
memory: Math.floor(process.memoryUsage().heapUsed / 1024 / 1024),
|
|
uptime: Date.now() - thisArg.readyAt
|
|
};
|
|
};
|
|
|
|
const shardResults = await shard.broadcastEval(evalFunc).catch((error) => this.client.logger.error(error));
|
|
const managerResult = await this.client.managerEval(`(${mEvalFunc})(this)`).catch((error) => this.client.logger.error(error));
|
|
|
|
const descValues = {
|
|
devs: await this.client.resolveUsers(this.client._options.bot.owners).then((owners) => {
|
|
return owners.map((o) => o.tag).join(', ');
|
|
}),
|
|
uptime: this.client.resolver.timeAgo(Math.floor(managerResult.uptime/1000)),
|
|
memory: managerResult.memory,
|
|
shards: shard.count
|
|
};
|
|
|
|
const shardValues = {
|
|
cachedUsers: this.client.users.cache.size,
|
|
guilds: this.client.guilds.cache.size,
|
|
channels: this.client.channels.cache.size,
|
|
uptime: this.client.resolver.timeAgo(Math.floor(this.client.uptime/1000)),
|
|
memory: Math.floor(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
};
|
|
|
|
const totalValues = shardResults.reduce((acc, curr) => {
|
|
Object.entries(curr).forEach(([key, val]) => {
|
|
if (!acc[key]) acc[key] = 0;
|
|
acc[key] += val;
|
|
});
|
|
return acc;
|
|
}, {});
|
|
totalValues.uptime = this.client.resolver.timeAgo(Math.floor(totalValues.uptime / 1000));
|
|
|
|
const embed = {
|
|
title: message.format('C_STATS_TITLE', {
|
|
client: this.client.user.tag,
|
|
version: require('../../../../../package.json').version
|
|
}),
|
|
description: message.format('C_STATS_DESC', descValues),
|
|
fields: [
|
|
{
|
|
name: message.format('C_STATS_CURRENT_SHARD', { shard: guild.shardID }),
|
|
value: message.format('C_STATS_CURRENT_SHARDS_VALUE', shardValues),
|
|
inline: true
|
|
},
|
|
{
|
|
name: message.format('C_STATS_TOTAL', { shards: shard.count }),
|
|
value: message.format('C_STATS_TOTAL_VALUE', totalValues),
|
|
inline: true
|
|
}
|
|
]
|
|
};
|
|
|
|
message.embed(embed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = StatsCommand; |