From 39b1c8d14bc1309783ada59931501306cde67d11 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 19 Jul 2024 18:22:04 +0100 Subject: [PATCH] Create allbalance command to get list of everyone's currency --- src/commands/allbalance.ts | 28 ++++++++++++++++++++++++++++ src/registry.ts | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 src/commands/allbalance.ts diff --git a/src/commands/allbalance.ts b/src/commands/allbalance.ts new file mode 100644 index 0000000..7db050a --- /dev/null +++ b/src/commands/allbalance.ts @@ -0,0 +1,28 @@ +import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js"; +import EmbedColours from "../constants/EmbedColours"; +import { Command } from "../type/command"; +import User from "../database/entities/app/User"; + +export default class AllBalance extends Command { + constructor() { + super(); + + this.CommandBuilder = new SlashCommandBuilder() + .setName("allbalance") + .setDescription("Get everyone's currency balance") + .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator); + } + + public override async execute(interaction: CommandInteraction) { + const users = await User.FetchAll(User); + + const filteredUsers = users.filter(x => x.Currency > 0); + + const embed = new EmbedBuilder() + .setColor(EmbedColours.Ok) + .setTitle("All Balances") + .setDescription(filteredUsers.map(x => `<@${x.Id}> ${x.Currency}`).join("\n")); + + await interaction.reply({ embeds: [ embed ], ephemeral: true }); + } +} \ No newline at end of file diff --git a/src/registry.ts b/src/registry.ts index 182418e..86b2b68 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -3,6 +3,7 @@ import { Environment } from "./constants/Environment"; // Global Command Imports import About from "./commands/about"; +import AllBalance from "./commands/allbalance"; import Balance from "./commands/balance"; import Daily from "./commands/daily"; import Drop from "./commands/drop"; @@ -31,6 +32,7 @@ export default class Registry { public static RegisterCommands() { // Global Commands CoreClient.RegisterCommand("about", new About()); + CoreClient.RegisterCommand("allbalance", new AllBalance()); CoreClient.RegisterCommand("balance", new Balance()); CoreClient.RegisterCommand("daily", new Daily()); CoreClient.RegisterCommand("drop", new Drop()); -- 2.43.4