diff --git a/shop/shop.py b/shop/shop.py index 83e54f2..ad795b7 100644 --- a/shop/shop.py +++ b/shop/shop.py @@ -1062,17 +1062,17 @@ class Shop(commands.Cog): async def redeem(self, interaction: discord.Interaction, button: discord.ui.Button): if interaction.user != ctx.author: return await interaction.response.send_message("This menu is not for you!", ephemeral=True) + await interaction.response.defer() self.value = True self.stop() - await interaction.response.defer() @discord.ui.button(label="Cancel", style=discord.ButtonStyle.red) async def cancel(self, interaction: discord.Interaction, button: discord.ui.Button): if interaction.user != ctx.author: return await interaction.response.send_message("This menu is not for you!", ephemeral=True) + await interaction.response.defer() self.value = False self.stop() - await interaction.response.defer() if data[item]["Type"].lower() == "role": prompt = f"{ctx.author.mention} Do you wish to redeem {item}? This will grant you the role assigned to this item and it will be removed from your inventory permanently." @@ -1095,9 +1095,11 @@ class Shop(commands.Cog): await self.assign_role(ctx, instance, item, data[item]["Role"]) else: await self.pending_add(ctx, item) - - sm = ShopManager(ctx, instance=None, user_data=instance) - await sm.remove(item) + async with instance.Inventory() as inv: + if item in inv: + inv[item]["Qty"] -= 1 + if inv[item]["Qty"] <= 0: + del inv[item] except Exception as exc: await msg.edit(content=f"An error occurred: {str(exc)}", view=None) @@ -1413,6 +1415,14 @@ class ShopManager: inv[item] = deepcopy(item_data) inv[item]["Qty"] = quantity + async def remove(self, item, number=1): + """Remove an item from user's inventory.""" + async with self.user_data.Inventory() as inv: + if item in inv: + inv[item]["Qty"] -= number + if inv[item]["Qty"] <= 0: + del inv[item] + class ItemManager: def __init__(self, ctx, instance):