diff --git a/src/buttonEvents/Claim.ts b/src/buttonEvents/Claim.ts index ce04803..6f9ae58 100644 --- a/src/buttonEvents/Claim.ts +++ b/src/buttonEvents/Claim.ts @@ -10,6 +10,7 @@ export default class Claim extends ButtonEvent { const cardNumber = interaction.customId.split(' ')[1]; const claimId = interaction.customId.split(' ')[2]; + const droppedBy = interaction.customId.split(' ')[3]; const userId = interaction.user.id; const claimed = await eClaim.FetchOneByClaimId(claimId); @@ -19,8 +20,8 @@ export default class Claim extends ButtonEvent { return; } - if (claimId != CoreClient.ClaimId) { - await interaction.reply('This card has expired'); + if (claimId == CoreClient.ClaimId && userId != droppedBy) { + await interaction.reply('The latest dropped card can only be claimed by the user who dropped it'); return; } @@ -35,16 +36,10 @@ export default class Claim extends ButtonEvent { await inventory.Save(Inventory, inventory); const claim = new eClaim(claimId); + claim.SetInventory(inventory); + 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'); } } \ No newline at end of file diff --git a/src/buttonEvents/Reroll.ts b/src/buttonEvents/Reroll.ts index c1a54ea..bc91c90 100644 --- a/src/buttonEvents/Reroll.ts +++ b/src/buttonEvents/Reroll.ts @@ -45,7 +45,7 @@ export default class Reroll extends ButtonEvent { row.addComponents( new ButtonBuilder() - .setCustomId(`claim ${randomCard.CardNumber} ${claimId}`) + .setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`) .setLabel("Claim") .setStyle(ButtonStyle.Primary), new ButtonBuilder() diff --git a/src/commands/drop.ts b/src/commands/drop.ts index 5770903..7503bf7 100644 --- a/src/commands/drop.ts +++ b/src/commands/drop.ts @@ -51,7 +51,7 @@ export default class Drop extends Command { row.addComponents( new ButtonBuilder() - .setCustomId(`claim ${randomCard.CardNumber} ${claimId}`) + .setCustomId(`claim ${randomCard.CardNumber} ${claimId} ${interaction.user.id}`) .setLabel("Claim") .setStyle(ButtonStyle.Primary), new ButtonBuilder() @@ -76,7 +76,6 @@ export default class Drop extends Command { } } - CoreClient.ClaimId = claimId; } } \ No newline at end of file diff --git a/src/database/entities/app/Claim.ts b/src/database/entities/app/Claim.ts index 7e1c4f9..b4cde5e 100644 --- a/src/database/entities/app/Claim.ts +++ b/src/database/entities/app/Claim.ts @@ -17,6 +17,10 @@ export default class Claim extends AppBaseEntity { @ManyToOne(() => Inventory, x => x.Claims) Inventory: Inventory; + public SetInventory(inventory: Inventory) { + this.Inventory = inventory; + } + public static async FetchOneByClaimId(claimId: string): Promise { const repository = AppDataSource.getRepository(Claim);