From 928a21d810ac32b5152debcacc96995083efa03f Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 26 May 2025 01:57:22 -0400 Subject: [PATCH] Refactor Shop cog to improve role refund functionality by separating user and settings instances. Enhance inventory management for role items by ensuring user-specific checks and maintaining item data integrity during refunds. --- shop/shop.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/shop/shop.py b/shop/shop.py index d4b626e..7daf8ed 100644 --- a/shop/shop.py +++ b/shop/shop.py @@ -407,7 +407,8 @@ class Shop(commands.Cog): [p]shop refund VIP Role """ try: - instance = await self.get_instance(ctx, settings=True) + settings = await self.get_instance(ctx, settings=True) + user_instance = await self.get_instance(ctx, user=ctx.author) except AttributeError: return await ctx.send("You can't use this command in DMs when not in global mode.") @@ -416,13 +417,14 @@ class Shop(commands.Cog): role_name = None shop_name = None - async with instance.Shops() as shops: + async with settings.Shops() as shops: for shop in shops.values(): for item_name, item_data in shop["Items"].items(): if (item_name.lower() == item.lower() and item_data["Type"].lower() == "role"): role_item = item_name role_name = item_data["Role"] + item_data = deepcopy(item_data) # Store for later use break if role_item: break @@ -482,14 +484,14 @@ class Shop(commands.Cog): try: await ctx.author.remove_roles(role, reason="Shop role refund") # Add the role item back to inventory - async with instance.Inventory() as inv: + async with user_instance.Inventory() as inv: if role_item in inv: inv[role_item]["Qty"] += 1 else: inv[role_item] = { "Qty": 1, "Type": "role", - "Info": f"Grants the {role.name} role", + "Info": item_data["Info"], "Role": role_name }