Fix user being able to claim cards with a 0 balance
This commit is contained in:
parent
cfcc8ad100
commit
837013835e
3 changed files with 46 additions and 13 deletions
|
@ -11,6 +11,7 @@ import CardConstants from "../constants/CardConstants";
|
|||
export default class Claim extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
if (!interaction.guild || !interaction.guildId) return;
|
||||
if (!interaction.channel) return;
|
||||
|
||||
await interaction.deferUpdate();
|
||||
|
||||
|
@ -21,15 +22,26 @@ export default class Claim extends ButtonEvent {
|
|||
|
||||
AppLogger.LogSilly("Button/Claim", `Parameters: cardNumber=${cardNumber}, claimId=${claimId}, droppedBy=${droppedBy}, userId=${userId}`);
|
||||
|
||||
const user = await User.FetchOneById(User, userId) || new User(userId, CardConstants.StartingCurrency);
|
||||
|
||||
AppLogger.LogSilly("Button/Claim", `${user.Id} has ${user.Currency} currency`);
|
||||
|
||||
if (!user.RemoveCurrency(CardConstants.ClaimCost)) {
|
||||
await interaction.channel.send(`${interaction.user}, Not enough currency! You need ${CardConstants.ClaimCost} currency, you have ${user.Currency}!`);
|
||||
return;
|
||||
}
|
||||
|
||||
await user.Save(User, user);
|
||||
|
||||
const claimed = await eClaim.FetchOneByClaimId(claimId);
|
||||
|
||||
if (claimed) {
|
||||
await interaction.reply("This card has already been claimed");
|
||||
await interaction.channel.send(`${interaction.user}, This card has already been claimed!`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (claimId == CoreClient.ClaimId && userId != droppedBy) {
|
||||
await interaction.reply("The latest dropped card can only be claimed by the user who dropped it");
|
||||
await interaction.channel.send(`${interaction.user}, The latest dropped card can only be claimed by the user who dropped it!`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -43,17 +55,6 @@ export default class Claim extends ButtonEvent {
|
|||
|
||||
await inventory.Save(Inventory, inventory);
|
||||
|
||||
const user = await User.FetchOneById(User, userId) || new User(userId, CardConstants.StartingCurrency);
|
||||
|
||||
AppLogger.LogSilly("Button/Claim", `${user.Id} has ${user.Currency} currency`);
|
||||
|
||||
if (!user.RemoveCurrency(CardConstants.ClaimCost)) {
|
||||
await interaction.reply(`Not enough currency! You need 10 currency, you have ${user.Currency}`);
|
||||
return;
|
||||
}
|
||||
|
||||
await user.Save(User, user);
|
||||
|
||||
const claim = new eClaim(claimId);
|
||||
claim.SetInventory(inventory);
|
||||
|
||||
|
|
|
@ -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 Reroll extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
|
@ -23,6 +25,20 @@ export default class Reroll extends ButtonEvent {
|
|||
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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue