diff --git a/package.json b/package.json index 91030275f..d3a4728ab 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "discord.js": "^14.13.0", "gif-encoder-2": "^1.0.5", "jszip": "^3.10.1", - "linux-os-info": "^2.0.0", "ts-node": "^10.9.1", "tsconfig-paths": "^4.2.0" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e2cb0265e..afd3d536e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,9 +29,6 @@ dependencies: jszip: specifier: ^3.10.1 version: 3.10.1 - linux-os-info: - specifier: ^2.0.0 - version: 2.0.0 ts-node: specifier: ^10.9.1 version: 10.9.1(@types/node@20.8.7)(typescript@5.2.2) @@ -711,10 +708,6 @@ packages: immediate: 3.0.6 dev: false - /linux-os-info@2.0.0: - resolution: {integrity: sha512-ZopyH4kT2Ehnmix8iUgS/41pfv7fSlUV1JukIn3DB3qD3byvhBNtgCbUApoAtiqcHRLKXCY3zakXlJgiExm2Qg==} - dev: false - /lodash.snakecase@4.1.1: resolution: {integrity: sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==} dev: false diff --git a/src/commands/bot/stats.ts b/src/commands/bot/stats.ts index 3c6e24128..11bc3549d 100644 --- a/src/commands/bot/stats.ts +++ b/src/commands/bot/stats.ts @@ -1,8 +1,6 @@ import { SlashCommand, SlashCommandI } from "@interfaces"; import { SlashCommandBuilder, Collection, Guild, version as djsVersion } from "discord.js"; -import { Client, EmbedBuilder, ChatInputCommandInteraction, Message } from "@client"; -import os from "os"; -import linuxOs from "linux-os-info"; +import { EmbedBuilder, ChatInputCommandInteraction, Message } from "@client"; import axios from "axios"; export const command: SlashCommand = { @@ -27,19 +25,14 @@ export const command: SlashCommand = { .set("bot", async (interaction: ChatInputCommandInteraction) => { // easier to get extended properties const client = interaction.client; - let sumMembers = 0; - let version: string; + const sumMembers = client.guilds.cache.reduce( + (acc: number, guild: Guild) => acc + guild.memberCount, + 0, + ); - client.guilds.cache.each((guild: Guild) => { - sumMembers += guild.memberCount; - }); - - const number = [...client.commandsProcessed.values()].reduce((a, b) => a + b, 0) + 1; - - if (os.platform() == "linux") version = linuxOs({ mode: "sync" }).pretty_name; - else version = os.version(); - - const image: string = (await axios.get(`${client.tokens.apiUrl}settings/images.heart`)).data; + const commandCount = + [...client.commandsProcessed.values()].reduce((acc, cur) => acc + cur, 0) + 1; + const heart: string = (await axios.get(`${client.tokens.apiUrl}settings/images.heart`)).data; const embed = new EmbedBuilder() .setTitle(`${client.user.username}'s Statistics`) @@ -60,72 +53,63 @@ export const command: SlashCommand = { { name: "Discord Library", value: `Discord.js ${djsVersion}`, inline: true }, { name: "Node.js", value: `${process.version}`, inline: true }, { name: "Total Commands", value: `${client.slashCommands.size}`, inline: true }, - { name: "Commands Processed", value: `${number}`, inline: true }, + { name: "Commands Processed", value: `${commandCount}`, inline: true }, { name: "Members Across Servers", value: `${sumMembers}`, inline: true }, - { name: "Operating System", value: version }, ) .setFooter({ text: "Made with love", - iconURL: image, + iconURL: heart, }); interaction .reply({ embeds: [embed], fetchReply: true }) .then((message: Message) => message.deleteButton()); }) .set("command", async (interaction: ChatInputCommandInteraction) => { - //if the command args are provided and the command does not exist in commandsProcessed: - if ( - interaction.options.getString("command") && - interaction.client.commandsProcessed.get(interaction.options.getString("command")) === - undefined - ) - return interaction.reply({ - ephemeral: true, - content: interaction - .strings() - .command.stats.not_found.replace("%COMMAND%", interaction.options.getString("command")), - }); + const command = interaction.options.getString("command"); + if (command) { + // command doesn't exist + if (interaction.client.commandsProcessed.get(command) === undefined) + return interaction.reply({ + ephemeral: true, + content: interaction.strings().command.stats.not_found.replace("%COMMAND%", command), + }); - if (interaction.options.getString("command")) { const embed = new EmbedBuilder().setTimestamp().setTitle( interaction .strings() - .command.stats.usage.replace("%COMMAND%", interaction.options.getString("command")) - .replace( - "%USE%", - interaction.client.commandsProcessed - .get(interaction.options.getString("command")) - .toString() ?? "0", - ), - ); - interaction.reply({ ephemeral: true, embeds: [embed] }); - } else { - //sorts commands by usage: 4,3,2,1 - const sorted = new Map( - [...interaction.client.commandsProcessed.entries()].sort((a, b) => b[1] - a[1]), + .command.stats.usage.replace("%COMMAND%", command) + .replace("%USE%", interaction.client.commandsProcessed.get(command).toString() ?? "0"), ); - const data = [[...sorted.keys()], [...sorted.values()]]; - const embed = new EmbedBuilder() - .setTimestamp() - .setTitle(interaction.strings().command.stats.top_ten).setDescription(` -${data[0] - .slice(0, data[0].length > 10 ? 10 : data[0].length) - .map((key: any, index: any) => { - let place = `\`${index + 1 < 10 ? ` ${index + 1}` : index + 1}.`; - place += ` `.repeat(4 - place.length); - place += "`"; - let command = `\`${key}`; - command += ` `.repeat(13 - command.length); - command += "`"; - let uses = `\`${data[1][index]}`; - uses += "`"; + return interaction.reply({ ephemeral: true, embeds: [embed] }); + } - return `${place} ${command} - ${uses}`; - }) - .join("\n")}`); + //sorts commands by usage: 4,3,2,1 + const sorted = new Map( + [...interaction.client.commandsProcessed.entries()].sort((a, b) => b[1] - a[1]), + ); + const data = [[...sorted.keys()], [...sorted.values()]]; - interaction.reply({ ephemeral: true, embeds: [embed] }); - } + interaction.reply({ + ephemeral: true, + embeds: [ + new EmbedBuilder() + .setTimestamp() + .setTitle(interaction.strings().command.stats.top_ten) + .setDescription( + data[0] + .slice(0, data[0].length > 10 ? 10 : data[0].length) + .map((key: any, index: any) => { + let place = `\`${index + 1 < 10 ? ` ${index + 1}` : index + 1}.`; + place += ` `.repeat(4 - place.length) + "`"; + let command = `\`${key}`; + command += ` `.repeat(13 - command.length) + "`"; + const uses = `\`${data[1][index]}\``; + return `${place} ${command} - ${uses}`; + }) + .join("\n"), + ), + ], + }); }), };