Ethan Lane
097b7284e6
- Fix list on `/allbalance` command not being sorted by currency #260 Reviewed-on: #320 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
29 lines
No EOL
1.1 KiB
TypeScript
29 lines
No EOL
1.1 KiB
TypeScript
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)
|
|
.sort((a, b) => b.Currency - a.Currency);
|
|
|
|
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 });
|
|
}
|
|
} |