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.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

This commit is contained in:
Valerie 2025-05-26 01:57:22 -04:00
parent 12bd541b64
commit 928a21d810

View file

@ -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
}