diff --git a/commands/general/count.js b/commands/general/count.js index 64f46d3..c969b5a 100644 --- a/commands/general/count.js +++ b/commands/general/count.js @@ -8,15 +8,19 @@ class CountCommand extends Command { if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return `${this.message.author.mention}, I don't have the \`Embed Links\` permission!`; const counts = await database.getCounts(); const countArray = []; - const sortedValues = counts.sort((a, b) => { + for (const entry of Object.entries(counts)) { + countArray.push(entry); + } + const sortedValues = countArray.sort((a, b) => { return b[1] - a[1]; }); + const countArray2 = []; for (const [key, value] of sortedValues) { - countArray.push(`**${key}**: ${value}`); + countArray2.push(`**${key}**: ${value}`); } const embeds = []; - const groups = countArray.map((item, index) => { - return index % 15 === 0 ? countArray.slice(index, index + 15) : null; + const groups = countArray2.map((item, index) => { + return index % 15 === 0 ? countArray2.slice(index, index + 15) : null; }).filter((item) => { return item; }); diff --git a/commands/general/help.js b/commands/general/help.js index 022b0d1..9188e0a 100644 --- a/commands/general/help.js +++ b/commands/general/help.js @@ -14,12 +14,12 @@ class HelpCommand extends Command { if (this.args.length !== 0 && (commands.has(this.args[0].toLowerCase()) || aliases.has(this.args[0].toLowerCase()))) { const command = aliases.has(this.args[0].toLowerCase()) ? collections.aliases.get(this.args[0].toLowerCase()) : this.args[0].toLowerCase(); const info = collections.info.get(command); - const countDB = await database.getCounts(); - const counts = countDB.reduce((acc, val) => { + const counts = await database.getCounts(); + /*const counts = countDB.reduce((acc, val) => { const [key, value] = val; acc[key] = value; return acc; - }, {}); + }, {});*/ const embed = { "embed": { "author": { diff --git a/shard.js b/shard.js index 0ce1c5c..79e8ecd 100644 --- a/shard.js +++ b/shard.js @@ -85,6 +85,8 @@ connected_workers ${image.connections.length} # TYPE queued_jobs gauge # HELP max_jobs Number of max allowed jobs on this worker # TYPE max_jobs gauge +# HELP command_count Number of times a command has been run +# TYPE command_count counter `); const servers = await image.getStatus(); for (const [i, w] of servers.entries()) { @@ -92,6 +94,10 @@ connected_workers ${image.connections.length} res.write(`queued_jobs{worker="${i}"} ${w.queued}\n`); res.write(`max_jobs{worker="${i}"} ${w.max}\n`); } + const counts = await database.getCounts(); + for (const [i, w] of Object.entries(counts)) { + res.write(`command_count{command="${i}"} ${w}\n`); + } res.end(); }); httpServer.listen(process.env.METRICS, () => { @@ -146,7 +152,6 @@ connected_workers ${image.connections.length} if (result) return this.ipc.broadcast("reloadFail", { result: result }); const result2 = await handler.load(collections.paths.get(message.cmd)); if (result2) return this.ipc.broadcast("reloadFail", { result: result2 }); - //return this.ipc.broadcast("reloadSuccess", this.clusterID); return this.ipc.broadcast("reloadSuccess"); }); diff --git a/utils/database/postgresql.js b/utils/database/postgresql.js index a8dc8aa..9224278 100644 --- a/utils/database/postgresql.js +++ b/utils/database/postgresql.js @@ -51,11 +51,12 @@ exports.enableChannel = async (channel) => { exports.getCounts = async () => { const counts = await connection.query("SELECT * FROM counts"); - const countArray = []; + //const countArray = []; + const countObject = {}; for (const { command, count } of counts.rows) { - countArray.push([command, count]); + countObject[command] = count; } - return countArray; + return countObject; }; exports.addCount = async (command) => {