Fix user being able to claim cards with a 0 balance

This commit is contained in:
Ethan Lane 2024-06-02 15:39:24 +01:00
parent cfcc8ad100
commit 837013835e
3 changed files with 46 additions and 13 deletions

View file

@ -8,6 +8,8 @@ import Config from "../database/entities/app/Config";
import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata";
import path from "path";
import AppLogger from "../client/appLogger";
import User from "../database/entities/app/User";
import CardConstants from "../constants/CardConstants";
export default class Drop extends Command {
constructor() {
@ -31,6 +33,20 @@ export default class Drop extends Command {
return;
}
let user = await User.FetchOneById(User, interaction.user.id);
if (!user) {
user = new User(interaction.user.id, CardConstants.StartingCurrency);
await user.Save(User, user);
AppLogger.LogInfo("Commands/Drop", `New user (${interaction.user.id}) saved to the database`);
}
if (user.Currency < CardConstants.ClaimCost) {
await interaction.reply(`Not enough currency! You need ${CardConstants.ClaimCost} currency, you have ${user.Currency}!`);
return;
}
const randomCard = CardDropHelperMetadata.GetRandomCard();
if (!randomCard) {