diff --git a/shop/shop.py b/shop/shop.py index eb7bdc6..83e54f2 100644 --- a/shop/shop.py +++ b/shop/shop.py @@ -967,6 +967,58 @@ class Shop(commands.Cog): return await ctx.send(embed=embed) try: + # Check if user already has the role + if role in ctx.author.roles: + # Ask if they want to remove the role and get a refund + embed = discord.Embed( + title="Role Already Owned", + description=f"You already have the `{role.name}` role. Would you like to remove it and get a refund?", + color=discord.Color.blue() + ) + msg = await ctx.send(embed=embed) + + # Add reactions for yes/no + await msg.add_reaction("✅") + await msg.add_reaction("❌") + + def check(reaction, user): + return user == ctx.author and str(reaction.emoji) in ["✅", "❌"] + + try: + reaction, user = await ctx.bot.wait_for("reaction_add", timeout=30.0, check=check) + if str(reaction.emoji) == "✅": + await ctx.author.remove_roles(role, reason="Shop role token was refunded.") + # Add the role item back to inventory + async with instance.Inventory() as inv: + if item in inv: + inv[item]["Qty"] += 1 + else: + inv[item] = {"Qty": 1, "Type": "role", "Info": f"Grants the {role.name} role", "Role": role_name} + + embed = discord.Embed( + title="Role Removed", + description=f"The `{role.name}` role has been removed and refunded to your inventory.", + color=discord.Color.green() + ) + await msg.edit(embed=embed) + return + else: + embed = discord.Embed( + title="Action Cancelled", + description="Role removal cancelled.", + color=discord.Color.red() + ) + await msg.edit(embed=embed) + return + except asyncio.TimeoutError: + embed = discord.Embed( + title="Timed Out", + description="Role removal timed out.", + color=discord.Color.red() + ) + await msg.edit(embed=embed) + return + await ctx.author.add_roles(role, reason="Shop role token was redeemed.") except discord.Forbidden: embed = discord.Embed( @@ -981,8 +1033,12 @@ class Shop(commands.Cog): await ctx.send(embed=embed) return False - sm = ShopManager(ctx, None, instance) - await sm.remove(item) + # Remove the item from inventory + async with instance.Inventory() as inv: + if item in inv: + inv[item]["Qty"] -= 1 + if inv[item]["Qty"] <= 0: + del inv[item] embed = discord.Embed( title="Role Assigned",