import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ContainerBuilder, MessageFlags, SectionBuilder, SeparatorSpacingSize, TextDisplayBuilder, version as djs_version } from 'discord.js'; import getQuickDBPing from '../../../utils/dbPing.js'; import getUptimeTimestamp from '../../../utils/uptime.js'; import emojis from '../../../config/emojis.js'; import os from 'os'; export const data = { name: 'stats', description: 'shows bot statistics.', category: 'general', aliases: ['statistics'], async execute(message, args, client) { const msg = await message.reply({ components: [ new ContainerBuilder().addTextDisplayComponents( new TextDisplayBuilder() .setContent(`${emojis.loading} **Fetching Statistics of Zyren**`) ) ], flags: MessageFlags.IsComponentsV2 }); const apiPing = client.ws.ping; const start = Date.now(); const dbPing = await getQuickDBPing(); const clientPing = Date.now() - start; const version = "2.0.0"; const uptime = getUptimeTimestamp(client); const libraryUsed = "discord.js"; const totalGuilds = client.guilds.cache.size; const totalUsers = client.users.cache.size; const totalChannels = client.channels.cache.size; const totalEmojis = client.emojis.cache.size; const currentShard = client.shard?.ids[0] || 0; const totalMemory = (os.totalmem() / 1024 / 1024 / 1024).toFixed(2); const memoryUsed = (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2); const freeMemory = (os.freemem() / 1024 / 1024 / 1024).toFixed(2); const cpuUsage = (process.cpuUsage().user / 1024 / 1024).toFixed(2); const cpuFree = (100 - (os.loadavg()[0] * 10)).toFixed(2); const cpuModel = os.cpus()[0].model; const cpuCore = os.cpus().length; const generalSection = new SectionBuilder() .addTextDisplayComponents( new TextDisplayBuilder().setContent( `${emojis.general} __**General**__\n> **Bot Version**: \`${version}\`\n` + `> **Bot Mention**: ${client.user}\n` + `> **Library**: \`${libraryUsed}\`\n` + `> **Uptime**: ${uptime}\n` + `> **Websocket Latency**: \`${apiPing}\` ms\n` + `> **Client Latency**: \`${clientPing}\` ms\n` + `> **Database Latency**: \`${dbPing}\` ms\n` + `> **Discord.js Version**: \`${djs_version}\`\n` + `> **Shard Id**: \`${currentShard}\`\n` + `> **Total Guilds**: \`${totalGuilds}\`\n` + `> **Total Users**: \`${totalUsers}\`\n` + `> **Total Channels**: \`${totalChannels}\`\n` + `> **Total Emojis**: \`${totalEmojis}\`` ) ); const systemSection = new SectionBuilder() .addTextDisplayComponents( new TextDisplayBuilder().setContent( `${emojis.system} __**System**__\n> **Operating System**: \`${os.platform()}\`\n` + `> **CPU Model**: \`${cpuModel}\`\n` + `> **CPU Cores**: \`${cpuCore}\`\n` + `> **CPU Usage**: \`${cpuUsage}\` %\n` + `> **CPU Free**: \`${cpuFree}\` %\n` + `> **Total Memory**: \`${totalMemory}\` GiB\n` + `> **Memory Used**: \`${memoryUsed}\` MiB\n` + `> **Free Memory**: \`${freeMemory}\` GiB\n` ) ); const teamSection = new SectionBuilder() .addTextDisplayComponents( new TextDisplayBuilder().setContent( `# ${emojis.member} __**Team Information**__\n${emojis.developer} **Developers:**\n` + `- [kyxen.msi](https://discord.com/users/1285094333086957599)\n` + `${emojis.coreteam} **Core Team:**\n` + `- [dibakarog](https://discord.com/users/845882321382801439)` ) ); const container = new ContainerBuilder() .addSectionComponents(generalSection) .addSeparatorComponents(separator => separator.setSpacing(SeparatorSpacingSize.Large)); const generalButton = new ButtonBuilder() .setCustomId('general') .setLabel('General') .setStyle(ButtonStyle.Primary); const systemButton = new ButtonBuilder() .setCustomId('system') .setLabel('System') .setStyle(ButtonStyle.Secondary); const teamButton = new ButtonBuilder() .setCustomId('team') .setLabel('Team') .setStyle(ButtonStyle.Secondary); const actionRow = new ActionRowBuilder() .addComponents(generalButton, systemButton, teamButton); await msg.edit({ components: [container, actionRow], flags: MessageFlags.IsComponentsV2 }); const collector = msg.createMessageComponentCollector({ time: 60000 }); collector.on('collect', async (interaction) => { if (interaction.user.id !== message.author.id) { return interaction.reply({ content: "Only the command author can use this", flags: MessageFlags.Ephemeral }); } const updatedGeneralButton = new ButtonBuilder() .setCustomId('general') .setLabel('General') .setStyle(interaction.customId === 'general' ? ButtonStyle.Primary : ButtonStyle.Secondary); const updatedSystemButton = new ButtonBuilder() .setCustomId('system') .setLabel('System') .setStyle(interaction.customId === 'system' ? ButtonStyle.Primary : ButtonStyle.Secondary); const updatedTeamButton = new ButtonBuilder() .setCustomId('team') .setLabel('Team') .setStyle(interaction.customId === 'team' ? ButtonStyle.Primary : ButtonStyle.Secondary); const updatedActionRow = new ActionRowBuilder() .addComponents(updatedGeneralButton, updatedSystemButton, updatedTeamButton); let contentContainer; switch (interaction.customId) { case 'general': contentContainer = new ContainerBuilder() .addSectionComponents(generalSection); break; case 'system': contentContainer = new ContainerBuilder() .addSectionComponents(systemSection); break; case 'team': contentContainer = new ContainerBuilder() .addSectionComponents(teamSection); break; } await interaction.update({ components: [contentContainer, updatedActionRow], flags: MessageFlags.IsComponentsV2 }); }); collector.on('end', async () => { const disabledGeneralButton = new ButtonBuilder() .setCustomId('general') .setLabel('General') .setStyle(ButtonStyle.Secondary) .setDisabled(true); const disabledSystemButton = new ButtonBuilder() .setCustomId('system') .setLabel('System') .setStyle(ButtonStyle.Secondary) .setDisabled(true); const disabledTeamButton = new ButtonBuilder() .setCustomId('team') .setLabel('Team') .setStyle(ButtonStyle.Secondary) .setDisabled(true); const disabledActionRow = new ActionRowBuilder() .addComponents(disabledGeneralButton, disabledSystemButton, disabledTeamButton); await msg.edit({ components: [container, disabledActionRow], flags: MessageFlags.IsComponentsV2 }).catch(() => {}); }); } }