Skip to content

Commit

Permalink
Economy-Stats command
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Jul 18, 2024
1 parent a92460d commit ecfffc8
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions commands/Economy/economy-stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const Command = require('../../base/Command.js');
const { EmbedBuilder } = require('discord.js');
const { QuickDB } = require('quick.db');
const db = new QuickDB();

class EconomyStats extends Command {
constructor(client) {
super(client, {
name: 'economy-stats',
description: 'Get the total cash, bank, and balance of the entire economy',
category: 'Economy',
examples: ['economystats'],
aliases: ['etotal', 'econtotal', 'economystats', 'ecostats'],
usage: 'economy-stats',
guildOnly: true,
});
}

async run(msg, text) {
await msg.guild.members.fetch();
const currencySymbol = (await db.get(`servers.${msg.guild.id}.economy.symbol`)) || '$';
const usersData = (await db.get(`servers.${msg.guild.id}.users`)) || {};

let totalCash = 0n;
let totalBank = 0n;

for (const userId in usersData) {
const user = await this.client.users.cache.get(userId);
if (user) {
const cash = BigInt(usersData[userId].economy.cash || 0);
const bank = BigInt(usersData[userId].economy.bank || 0);
totalCash += cash;
totalBank += bank;
}
}

const totalBalance = totalCash + totalBank;

const embed = new EmbedBuilder()
.setColor(msg.settings.embedColor)
.setTitle(`${msg.guild.name}'s Economy Total`)
.setAuthor({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL() })
.setDescription(`Here are the totals for the entire economy:`)
.addFields(
{ name: 'Total Cash', value: `${currencySymbol}${totalCash.toLocaleString()}`, inline: false },
{ name: 'Total Bank', value: `${currencySymbol}${totalBank.toLocaleString()}`, inline: false },
{ name: 'Total Balance', value: `${currencySymbol}${totalBalance.toLocaleString()}`, inline: false },
)
.setTimestamp();

await msg.channel.send({ embeds: [embed] });
}
}

module.exports = EconomyStats;

0 comments on commit ecfffc8

Please sign in to comment.