Prevent users from being able to claim the latest card unless you were the one to drop it
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ethan Lane 2023-09-13 15:06:53 +01:00
parent ad505b3ea2
commit 8ccd7c33d4
4 changed files with 11 additions and 13 deletions

View file

@ -10,6 +10,7 @@ export default class Claim extends ButtonEvent {
const cardNumber = interaction.customId.split(' ')[1]; const cardNumber = interaction.customId.split(' ')[1];
const claimId = interaction.customId.split(' ')[2]; const claimId = interaction.customId.split(' ')[2];
const droppedBy = interaction.customId.split(' ')[3];
const userId = interaction.user.id; const userId = interaction.user.id;
const claimed = await eClaim.FetchOneByClaimId(claimId); const claimed = await eClaim.FetchOneByClaimId(claimId);
@ -19,8 +20,8 @@ export default class Claim extends ButtonEvent {
return; return;
} }
if (claimId != CoreClient.ClaimId) { if (claimId == CoreClient.ClaimId && userId != droppedBy) {
await interaction.reply('This card has expired'); await interaction.reply('The latest dropped card can only be claimed by the user who dropped it');
return; return;
} }
@ -35,16 +36,10 @@ export default class Claim extends ButtonEvent {
await inventory.Save(Inventory, inventory); await inventory.Save(Inventory, inventory);
const claim = new eClaim(claimId); const claim = new eClaim(claimId);
claim.SetInventory(inventory);
await claim.Save(eClaim, claim); await claim.Save(eClaim, claim);
inventory = await Inventory.FetchOneById(Inventory, inventory.Id, [ "Claims" ]);
if (inventory) {
inventory.AddClaim(claim);
await inventory.Save(Inventory, inventory);
}
await interaction.reply('Card claimed'); await interaction.reply('Card claimed');
} }
} }

View file

@ -45,7 +45,7 @@ export default class Reroll extends ButtonEvent {
row.addComponents( row.addComponents(
new ButtonBuilder() new ButtonBuilder()
.setCustomId(`claim ${randomCard.CardNumber} ${claimId}`) .setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`)
.setLabel("Claim") .setLabel("Claim")
.setStyle(ButtonStyle.Primary), .setStyle(ButtonStyle.Primary),
new ButtonBuilder() new ButtonBuilder()

View file

@ -51,7 +51,7 @@ export default class Drop extends Command {
row.addComponents( row.addComponents(
new ButtonBuilder() new ButtonBuilder()
.setCustomId(`claim ${randomCard.CardNumber} ${claimId}`) .setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`)
.setLabel("Claim") .setLabel("Claim")
.setStyle(ButtonStyle.Primary), .setStyle(ButtonStyle.Primary),
new ButtonBuilder() new ButtonBuilder()
@ -76,7 +76,6 @@ export default class Drop extends Command {
} }
} }
CoreClient.ClaimId = claimId; CoreClient.ClaimId = claimId;
} }
} }

View file

@ -17,6 +17,10 @@ export default class Claim extends AppBaseEntity {
@ManyToOne(() => Inventory, x => x.Claims) @ManyToOne(() => Inventory, x => x.Claims)
Inventory: Inventory; Inventory: Inventory;
public SetInventory(inventory: Inventory) {
this.Inventory = inventory;
}
public static async FetchOneByClaimId(claimId: string): Promise<Claim | null> { public static async FetchOneByClaimId(claimId: string): Promise<Claim | null> {
const repository = AppDataSource.getRepository(Claim); const repository = AppDataSource.getRepository(Claim);