from ast import alias from enum import member from locale import currency import discord from redbot.core import commands from .inventory import RPGInventory class RPGShops(commands.Cog): def __init__(self, rpg_cog): self.rpg_cog = rpg_cog self.config = self.rpg_cog default_guild = { "shops": {}, "status": { "active": bool, "deactive": bool, }, "currency": { "name": str, "symbol": str, "emoji": str, } } #self.config.register_guild(**default_guild_settings) # ----------------------------------------------------------------------------------------- # --------------- SHOP GROUP COMMANDS ----------------------------------------------------- # ----------------------------------------------------------------------------------------- @commands.group(name="shop", alias=["sp"]) async def shop(self, ctx): pass # Comes from Base Shop Group Above @shop.group(name="manager", alias=["mgr"]) async def manager(self, ctx): pass # Comes from Manager Group Above @manager.group(name="set", alias=["st"]) async def set(self, ctx): pass # Comes From Set Group From Above @set.group(name="status", alias=["sta"]) async def status(self, ctx): pass # Comes From Set Group From Above @set.group(name="currency", alias=["cur"]) async def currency(self, ctx): pass # ----------------------------------------------------------------------------------------- # ------------------ SHOP BASE COMMANDS -------------------------------------------------- # ----------------------------------------------------------------------------------------- @shop.command(name="buy", alias=["by"]) # shop buy async def buy(self, ctx, shop_name: str, item_name: str, quantity: int = 1): """ Buy an item from the shop. """ # Retrieve shop data shops = await self.config.guild(ctx.guild).shops.all() if shop_name not in shops: return await ctx.send(f"Shop '{shop_name}' not found.") shop_data = shops[shop_name] items = shop_data.get("items", {}) # Assuming you store items in an 'items' dictionary within the shop data if item_name not in items: return await ctx.send(f"Item '{item_name}' not found in '{shop_name}'.") item_data = items[item_name] price = item_data.get("price") stock = item_data.get("quantity") # Check if the shop has enough stock if stock is not None and stock < quantity: return await ctx.send(f"Not enough '{item_name}' in stock. Only {stock} available.") # Check if the user has enough currency currency_name = await self.config.guild(ctx.guild).shops_currency_name.get() user_balance = await self.rpg_cog.config.member(ctx.author).get_raw("gold") # Assuming gold is the currency total_cost = price * quantity if user_balance < total_cost: return await ctx.send(f"You don't have enough {currency_name} to buy {quantity} {item_name}(s).") # Deduct currency and add item to inventory await self.rpg_cog.config.member(ctx.author).set_raw("gold", value=user_balance - total_cost) await self.rpg_cog.inventory.add_item(ctx, ctx.author, item_name, quantity) # Update shop inventory (if applicable) if stock is not None: shop_data["items"][item_name]["quantity"] -= quantity await self.config.guild(ctx.guild).shops.set_raw(shop_name, value=shop_data) await ctx.send(f"You bought {quantity} {item_name}(s) for {total_cost} {currency_name}!") @shop.command(name="sell", alias=["sl"]) # shop sell async def buy(self, ctx, item_name: str): """ Sell an item back to the shop. """ # ... (logic to handle the purchase and currency) # Add the purchased item to the user's inventory await self.inventory.remove_item(ctx, ctx.author, item_name) @shop.command(name="give", alias=["gi"]) # shop give async def give(self, ctx, item_name: str, target: member): """ Give an item to another player. """ # ... (logic to handle the transfer of items between players) await self.inventory.remove_item(ctx, ctx.author, item_name) await self.inventory.add_item(ctx, target, item_name) @shop.command(name="list", alias=["ls"]) # shop list async def list(self, ctx, shop_name: str): """ List the items available in a shop. """ # ... (logic to retrieve and display the items in the shop) items = await self.rpg_cog.config.guild(ctx.guild).shops_items.get_raw(shop_name) prices = await self.rpg_cog.config.guild(ctx.guild).shops_prices.get_raw(shop_name) if items: item_list = "\n".join([f"{item} - {price}" for item, price in zip(items, prices)]) await ctx.send(f"Items available in {shop_name}:\n{item_list}") else: await ctx.send(f"No items available in {shop_name}.") # ----------------------------------------------------------------------------------------- # ------------------------- Manager Base Commands ----------------------------------------- # ----------------------------------------------------------------------------------------- @manager.command(name="create", alias=["cr"]) async def create_shop(self, ctx, shop_name: str, *, description: str): await ctx.send(f"Shop '{shop_name}' created!") @manager.command(name="delete", alias=["del"]) async def delete_shop(self, ctx, shop_name: str): await ctx.send(f"Shop '{shop_name}' deleted!") # ----------------------------------------------------------------------------------------- # --------------------------- SET BASE GROUP ---------------------------------------------- # ----------------------------------------------------------------------------------------- # --------------------------- STATUS BASE COMMANDS ---------------------------------------- # ----------------------------------------------------------------------------------------- @status.command(name="active", alias=["act"]) async def active_shop(self, ctx, shop_name: str): await ctx.send(f"Shop '{shop_name}' activated!") @status.command(name="deactive", alias=["deact"]) async def deactive_shop(self, ctx, shop_name: str): await ctx.send(f"Shop '{shop_name}' deactivated!") # ----------------------------------------------------------------------------------------- # --------------------------- CURRENCY BASE COMMANDS -------------------------------------- # ----------------------------------------------------------------------------------------- @currency.command(name="name", alias=["nm"]) # Use @currency.command async def name_currency(self, ctx, currency_name: str): await ctx.send(f"Currency name set to '{currency_name}'!") @currency.command(name="symbol", alias=["sym"]) # Use @currency.command async def symbol_currency(self, ctx, currency_symbol: str): await ctx.send(f"Currency symbol set to '{currency_symbol}'!") @currency.command(name="emoji", alias=["emo"]) # Use @currency.command async def emoji_currency(self, ctx, currency_emoji: str): await ctx.send(f"Currency emoji set to '{currency_emoji}'!")