Rename EconomyCog to Fun and update command descriptions for prefix usage

This commit is contained in:
pancakes-proxy 2025-05-10 21:15:27 +09:00
parent 4188233a22
commit 53575e22ca

View File

@ -20,7 +20,7 @@ SHOP_ITEMS = {
"RARE Golden Teto Plusie": 20000,
}
class EconomyCog(commands.Cog):
class Fun(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
# A simple in-memory economy store where each user starts with $100 and an empty inventory.
@ -32,12 +32,12 @@ class EconomyCog(commands.Cog):
self.economy[user_id] = {"balance": 100, "inventory": []}
return self.economy[user_id]
# Create a slash command group called "fun"
fun_group = app_commands.Group(name="fun", description="Fun economy commands")
# Create a prefix command group called "fun"
fun_group = commands.Group(name="fun", help="Fun economy commands")
@fun_group.command(name="work", description="Work a job and earn money!")
async def work(self, interaction: discord.Interaction):
account = self.get_account(interaction.user.id)
@fun_group.command(name="work", help="Work a job and earn money!")
async def work(self, ctx: commands.Context):
account = self.get_account(ctx.author.id)
earned = random.randint(50, 150)
job = random.choice(["barista", "cashier", "developer", "bartender", "freelancer"])
account["balance"] += earned
@ -45,10 +45,9 @@ class EconomyCog(commands.Cog):
f"You worked as a {job} and earned ${earned}.\nYour new balance is ${account['balance']}."
)
@fun_group.command(name="sell", description="Sell an item from your inventory.")
@app_commands.describe(item="The item you wish to sell.")
async def sell(self, interaction: discord.Interaction, item: str):
account = self.get_account(interaction.user.id)
@fun_group.command(name="sell", help="Sell an item from your inventory.")
async def sell(self, ctx: commands.Context, item: str):
account = self.get_account(ctx.author.id)
# Find the item in your inventory (ignoring case)
item_in_inventory = None
for inv_item in account["inventory"]:
@ -69,9 +68,8 @@ class EconomyCog(commands.Cog):
f"You sold your {item_in_inventory} for ${sold_price}.\nYour new balance is ${account['balance']}."
)
@fun_group.command(name="steal", description="Attempt to steal money from another user!")
@app_commands.describe(target="The member you want to steal from.")
async def steal(self, interaction: discord.Interaction, target: discord.Member):
@fun_group.command(name="steal", help="Attempt to steal money from another user!")
async def steal(self, ctx: commands.Context, target: discord.Member):
# Prevent stealing from oneself
if target.id == ctx.author.id:
await ctx.send("You can't steal from yourself!")
@ -100,10 +98,9 @@ class EconomyCog(commands.Cog):
f"You got caught trying to steal from {target.display_name}!\nYou were fined ${fine}.\nYour new balance is ${thief['balance']}."
)
@fun_group.command(name="shop", description="View shop items or buy an item.")
@app_commands.describe(item="The item you wish to buy (optional). Leave empty to view available items.")
async def shop(self, interaction: discord.Interaction, item: Optional[str] = None):
account = self.get_account(interaction.user.id)
@fun_group.command(name="shop", help="View shop items or buy an item.")
async def shop(self, ctx: commands.Context, item: Optional[str] = None):
account = self.get_account(ctx.author.id)
if item is None:
# List all available shop items.
items_list = "\n".join([f"{name.title()} - ${price}" for name, price in SHOP_ITEMS.items()])
@ -125,9 +122,8 @@ class EconomyCog(commands.Cog):
f"You bought a {item.title()} for ${price}.\nYour new balance is ${account['balance']}."
)
@fun_group.command(name="gamble", description="Gamble a certain amount of money in a coin flip!")
@app_commands.describe(amount="The amount of money you want to gamble.")
async def gamble(self, interaction: discord.Interaction, amount: int):
@fun_group.command(name="gamble", help="Gamble a certain amount of money in a coin flip!")
async def gamble(self, ctx: commands.Context, amount: int):
if amount <= 0:
await ctx.send("You must gamble a positive amount!")
return
@ -151,7 +147,7 @@ class EconomyCog(commands.Cog):
# The setup function to add this cog and register the command group.
async def setup(bot: commands.Bot):
cog = EconomyCog(bot)
cog = Fun(bot)
await bot.add_cog(cog)
# Register the entire /fun group to the bot's command tree.
bot.tree.add_command(Fun.fun_group)
# bot.tree.add_command(Fun.fun_group) # Removed slash command registration