From b8cd73c5700853ef9176dc59686720ead25d31fa Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 20 Jul 2024 21:42:37 +0100 Subject: [PATCH] Create allbalance command to get list of everyone's currency (#306) - Create `/allbalance` command for server administrators to be able to get a list of everyone's currency - This will allow admins to adjust and rebalance currency as desired #260 Reviewed-on: https://git.vylpes.xyz/External/card-drop/pulls/306 Reviewed-by: VylpesTester Co-authored-by: Ethan Lane Co-committed-by: Ethan Lane --- 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());