Skip to content
Merged

Dev #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bronxbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async def before_update_guilds(self):
bot = BronxBot(
command_prefix='.',
intents=intents,
shard_count=2,
shard_count=round(config['GUILD_COUNT']/20), # a shard for every 20 servers
case_insensitive=True,
application_id=config["CLIENT_ID"] # <-- Add this line
)
Expand Down
7 changes: 5 additions & 2 deletions cogs/LastFm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import discord
import discord
from discord.ext import commands
import aiohttp
import os
Expand Down Expand Up @@ -36,9 +36,12 @@ def get_lastfm_api_secret() -> Optional[str]:
except Exception:
continue
return None
with open("data/config.json", "r", encoding="utf-8") as f:
config = json.load(f)

LASTFM_API_KEY = get_lastfm_api_key()
LASTFM_API_SECRET = get_lastfm_api_secret()
#TODO: Migrate this to mongo

def load_links() -> dict:
if not os.path.exists(DATA_PATH):
Expand Down Expand Up @@ -106,7 +109,7 @@ def __init__(self, bot):
def get_auth_url(self, discord_id: int) -> str:
params = {
"api_key": LASTFM_API_KEY,
"cb": f"https://your-production-domain.com/api/lastfm/callback?discord_id={discord_id}"
"cb": f"https://bronxbot.onrender.com/api/lastfm/callback?discord_id={discord_id}"
}
return f"https://www.last.fm/api/auth/?{urlencode(params)}"

Expand Down
155 changes: 141 additions & 14 deletions cogs/economy/Bazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,17 @@ async def buy_items(self, interaction: discord.Interaction, button: discord.ui.B
await interaction.response.send_message("❌ No items available in the bazaar right now.", ephemeral=True)
return

# First send the select menu
modal = ItemSelectModal(self.cog, self.cog.current_items)
await interaction.response.send_message(
"Select an item to purchase:",
view=modal.select_view,
ephemeral=True
)

# Then send the modal for amount
await interaction.followup.send_modal(modal)
await interaction.response.send_modal(modal)

@discord.ui.button(label="📈 Buy Stock", style=discord.ButtonStyle.secondary)
async def buy_stock(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.cog.handle_stock_purchase(interaction)

@discord.ui.button(label="📉 Sell Stock", style=discord.ButtonStyle.secondary)
async def sell_stock(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.cog.handle_stock_sale(interaction)

@discord.ui.button(label="🗑️ Close", style=discord.ButtonStyle.danger)
async def close(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer()
Expand Down Expand Up @@ -225,7 +221,7 @@ async def reset_bazaar(self):
num_items = random.randint(3, 5)
self.current_items = random.sample(category_items, min(num_items, len(category_items)))

# Apply bazaar-specific modifications
# Apply bazaar specific modifications
for item in self.current_items:
# Apply random discount (10-30%)
discount = random.uniform(0.1, 0.3)
Expand Down Expand Up @@ -340,8 +336,9 @@ async def bazaar(self, ctx):
embed = discord.Embed(
title="🛒 The Wandering Bazaar",
description=f"*Exotic goods from distant lands*\n\n"
f"Your Bazaar Stock: **{user_stock}** (Discount: **{user_discount*100:.0f}%**)\n"
f"Current Stock Price: **{self.calculate_stock_price()}** {self.currency}",
f"Your Bazaar Stock: **{user_stock}** (Discount: **{user_discount*100:.0f}%**)\n"
f"Current Stock Price: **{self.calculate_stock_price()}** {self.currency}\n"
f"Sell Price: **{int(self.calculate_stock_price() * 0.8)}** {self.currency} (80%)",
color=0x9b59b6
)

Expand Down Expand Up @@ -381,12 +378,142 @@ async def bazaar(self, ctx):
message = await ctx.reply(embed=embed, view=view)
view.message = message

@commands.command(name="bazaar-buy", aliases=["bbuy"])
@commands.command(name="bazaarbuy", aliases=["bbuy"])
@commands.cooldown(1, 5, commands.BucketType.user)
async def bazaar_buy(self, ctx, item_id: str, amount: int = 1):
"""Buy an item from the bazaar"""
await self.handle_bazaar_purchase(ctx, item_id, amount)

@commands.command(name="bazaarsell", aliases=["bsell"])
@commands.cooldown(1, 10, commands.BucketType.user)
async def bazaar_sell(self, ctx, amount: int = 1):
"""Sell your bazaar stock"""
await self.handle_stock_sale(ctx, amount)

async def handle_stock_sale(self, interaction_or_ctx, amount: int = 1):
"""Handle stock sale from either interaction or command"""
is_interaction = isinstance(interaction_or_ctx, discord.Interaction)

if is_interaction:
interaction = interaction_or_ctx
user = interaction.user
guild = interaction.guild
respond = interaction.response.send_message
else:
ctx = interaction_or_ctx
user = ctx.author
guild = ctx.guild
respond = ctx.reply

if amount <= 0:
msg = "❌ Amount must be positive."
if is_interaction:
await respond(msg, ephemeral=True)
else:
await respond(msg)
return

# Get user's current stock
current_stock = await self.get_user_stock(user.id)

if current_stock < amount:
msg = f"❌ You only have {current_stock} stock to sell!"
if is_interaction:
await respond(msg, ephemeral=True)
else:
await respond(msg)
return

# Calculate sale price (80% of current stock price)
stock_price = int(self.calculate_stock_price() * 0.8)
total_gain = stock_price * amount

# For interactions, defer first
if is_interaction:
await interaction.response.defer()

# Add money to wallet
if not await db.update_wallet(user.id, total_gain, guild.id if guild else None):
msg = "❌ Failed to process sale. Please try again."
if is_interaction:
await interaction.followup.send(msg, ephemeral=True)
else:
await respond(msg)
return

# Remove stock
result = await db.db.users.update_one(
{"_id": str(user.id)},
{"$set": {"bazaar_stock": current_stock - amount}}
)

if result.modified_count == 0:
# Refund if failed
await db.update_wallet(user.id, -total_gain, guild.id if guild else None)
msg = "❌ Failed to remove stock. Transaction cancelled."
if is_interaction:
await interaction.followup.send(msg, ephemeral=True)
else:
await respond(msg)
return

# Get updated user data
new_stock = current_stock - amount
new_discount = self.calculate_discount(new_stock)
new_balance = await db.get_wallet_balance(user.id, guild.id if guild else None)

# Create embed
embed = discord.Embed(
title="✅ Stock Sale Complete",
description=f"You sold **{amount}** bazaar stock!",
color=0x00ff00
)

embed.add_field(
name="Sale Details",
value=f"Price per Stock: **{stock_price}** {self.currency}\n"
f"Total Gain: **{total_gain}** {self.currency}",
inline=False
)

embed.add_field(
name="Your New Holdings",
value=f"Remaining Stock: **{new_stock}**\n"
f"Current Discount: **{new_discount*100:.0f}%**\n"
f"New Balance: **{new_balance}** {self.currency}",
inline=False
)

# Check if they lost secret shop access
if new_stock < self.stock_threshold and current_stock >= self.stock_threshold:
embed.add_field(
name="🔒 Secret Shop Lost",
value=f"You no longer meet the {self.stock_threshold} stock requirement for secret shop access!",
inline=False
)

try:
if hasattr(self, 'last_stock_message') and self.last_stock_message:
# Edit the existing message
if is_interaction:
await self.last_stock_message.edit(embed=embed)
else:
await self.last_stock_message.edit(embed=embed)
else:
# Send new message and store reference
if is_interaction:
msg = await interaction.followup.send(embed=embed)
else:
msg = await respond(embed=embed)
self.last_stock_message = msg
except Exception as e:
self.logger.error(f"Error updating stock sale message: {e}")
# Fallback to sending new message if edit fails
if is_interaction:
await interaction.followup.send(embed=embed)
else:
await respond(embed=embed)

async def handle_bazaar_purchase(self, interaction_or_ctx, item_id: str = None, amount: int = 1):
"""Handle bazaar purchase from either interaction or command"""
is_interaction = isinstance(interaction_or_ctx, discord.Interaction)
Expand Down Expand Up @@ -554,7 +681,7 @@ async def handle_bazaar_purchase(self, interaction_or_ctx, item_id: str = None,
else:
await respond(embed=embed)

@commands.command(name="bazaar-stock", aliases=["bstock"])
@commands.command(name="bazaarstock", aliases=["bstock"])
@commands.cooldown(1, 10, commands.BucketType.user)
async def bazaar_stock(self, ctx, amount: int = 1):
"""Buy bazaar stock"""
Expand Down
1 change: 1 addition & 0 deletions cogs/economy/Economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ async def rob(self, ctx, victim: discord.Member):
fine = int((random.random() * 0.3 + 0.1) * victim_bal)

await db.update_wallet(ctx.author.id, -fine, ctx.guild.id)
await db.update_wallet(victim.id, fine, ctx.guild.id)
return await ctx.reply(f"You got caught and paid **{fine}** {self.currency} in fines!")

stolen = int(victim_bal * random.uniform(0.1, 0.5))
Expand Down
8 changes: 4 additions & 4 deletions cogs/economy/Gambling.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,9 @@ async def _run_crash_game(self, ctx, view, bet: int, current_balance: int):
increment = 0.1
crash_point = random.uniform(1.1, 2.0) # Determine crash point first

# 1 in 1000 chance for big multiplier
# 1 in 1000 chance for a big multiplier
if random.random() < 0.001:
crash_point = random.uniform(100.0, 1000.0)
crash_point = random.uniform(10.0, 1000000.0)

while True:
# First check if we've reached crash point
Expand Down Expand Up @@ -480,7 +480,7 @@ async def _run_crash_game(self, ctx, view, bet: int, current_balance: int):
self.active_games.remove(ctx.author.id)
return

await asyncio.sleep(0.5)
await asyncio.sleep(0.75)

def _crash_view(self, user_id: int, bet: int, current_balance: int):
"""Create the crash game view with cashout button"""
Expand Down Expand Up @@ -951,7 +951,7 @@ async def roulette(self, ctx, bet: str = None, choice: str = None):
message = await ctx.reply(embed=embed)

# Animation sequence
spin_duration = 3 # seconds
spin_duration = 5 # seconds
spin_steps = 10
delay = spin_duration / spin_steps

Expand Down
31 changes: 29 additions & 2 deletions cogs/economy/Work.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,36 @@ def __init__(self, bot):
@commands.cooldown(1, 60, commands.BucketType.user)
async def work(self, ctx):
"""Work for some money"""
amount = random.randint(50, 200)
amount = random.randint(100, 1800)
await db.update_wallet(ctx.author.id, amount, ctx.guild.id)
await ctx.reply(f"You worked and earned **{amount}** {self.currency}")
responses = [
f"You worked hard and earned **{amount}** {self.currency}!",
f"Great effort! You just made **{amount}** {self.currency}.",
f"Your dedication paid off! You received **{amount}** {self.currency}.",
f"Well done! You've earned **{amount}** {self.currency}.",
f"Awesome work! You've collected **{amount}** {self.currency}.",
f"Success! You gained **{amount}** {self.currency} from your work.",
f"Keep it up! You earned **{amount}** {self.currency}.",
f"Fantastic job! You made **{amount}** {self.currency}.",
f"Your hard work has been rewarded with **{amount}** {self.currency}.",
f"You put in the effort and earned **{amount}** {self.currency}.",
f"Your labor was fruitful! You received **{amount}** {self.currency}.",
f"You've been productive! You earned **{amount}** {self.currency}.",
f"Your work ethic is impressive! You made **{amount}** {self.currency}.",
f"You've shown great diligence! You earned **{amount}** {self.currency}.",
f"Your commitment to work has paid off! You received **{amount}** {self.currency}.",
f"You've been industrious! You earned **{amount}** {self.currency}.",
f"Your efforts have been fruitful! You made **{amount}** {self.currency}.",
f"You've been a hard worker! You earned **{amount}** {self.currency}.",
f"You've shown great perseverance! You received **{amount}** {self.currency}.",
f"You've been diligent! You earned **{amount}** {self.currency}.",
f"You've been a model employee! You made **{amount}** {self.currency}.",
f"You've been a star worker! You earned **{amount}** {self.currency}.",
f"You've been a top performer! You received **{amount}** {self.currency}.",
f"You've been a valuable asset! You earned **{amount}** {self.currency}.",
f"You've been a key contributor! You made **{amount}** {self.currency}.",
]
await ctx.reply(random.choice(responses))


async def setup(bot):
Expand Down
21 changes: 0 additions & 21 deletions dashboard/api/index.py

This file was deleted.

51 changes: 0 additions & 51 deletions dashboard/api/lastfm_callback.py

This file was deleted.

Loading