Skip to content

Commit 53bfbf6

Browse files
authored
Merge pull request #17 from bronxbot/dev
Dev
2 parents 41bd510 + 7c182a8 commit 53bfbf6

29 files changed

Lines changed: 181 additions & 3408 deletions

bronxbot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async def before_update_guilds(self):
145145
bot = BronxBot(
146146
command_prefix='.',
147147
intents=intents,
148-
shard_count=2,
148+
shard_count=round(config['GUILD_COUNT']/20), # a shard for every 20 servers
149149
case_insensitive=True,
150150
application_id=config["CLIENT_ID"] # <-- Add this line
151151
)

cogs/LastFm.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import discord
1+
import discord
22
from discord.ext import commands
33
import aiohttp
44
import os
@@ -36,9 +36,12 @@ def get_lastfm_api_secret() -> Optional[str]:
3636
except Exception:
3737
continue
3838
return None
39+
with open("data/config.json", "r", encoding="utf-8") as f:
40+
config = json.load(f)
3941

4042
LASTFM_API_KEY = get_lastfm_api_key()
4143
LASTFM_API_SECRET = get_lastfm_api_secret()
44+
#TODO: Migrate this to mongo
4245

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

cogs/economy/Bazaar.py

Lines changed: 141 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,17 @@ async def buy_items(self, interaction: discord.Interaction, button: discord.ui.B
8888
await interaction.response.send_message("❌ No items available in the bazaar right now.", ephemeral=True)
8989
return
9090

91-
# First send the select menu
9291
modal = ItemSelectModal(self.cog, self.cog.current_items)
93-
await interaction.response.send_message(
94-
"Select an item to purchase:",
95-
view=modal.select_view,
96-
ephemeral=True
97-
)
98-
99-
# Then send the modal for amount
100-
await interaction.followup.send_modal(modal)
92+
await interaction.response.send_modal(modal)
10193

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

98+
@discord.ui.button(label="📉 Sell Stock", style=discord.ButtonStyle.secondary)
99+
async def sell_stock(self, interaction: discord.Interaction, button: discord.ui.Button):
100+
await self.cog.handle_stock_sale(interaction)
101+
106102
@discord.ui.button(label="🗑️ Close", style=discord.ButtonStyle.danger)
107103
async def close(self, interaction: discord.Interaction, button: discord.ui.Button):
108104
await interaction.response.defer()
@@ -225,7 +221,7 @@ async def reset_bazaar(self):
225221
num_items = random.randint(3, 5)
226222
self.current_items = random.sample(category_items, min(num_items, len(category_items)))
227223

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

@@ -381,12 +378,142 @@ async def bazaar(self, ctx):
381378
message = await ctx.reply(embed=embed, view=view)
382379
view.message = message
383380

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

387+
@commands.command(name="bazaarsell", aliases=["bsell"])
388+
@commands.cooldown(1, 10, commands.BucketType.user)
389+
async def bazaar_sell(self, ctx, amount: int = 1):
390+
"""Sell your bazaar stock"""
391+
await self.handle_stock_sale(ctx, amount)
392+
393+
async def handle_stock_sale(self, interaction_or_ctx, amount: int = 1):
394+
"""Handle stock sale from either interaction or command"""
395+
is_interaction = isinstance(interaction_or_ctx, discord.Interaction)
396+
397+
if is_interaction:
398+
interaction = interaction_or_ctx
399+
user = interaction.user
400+
guild = interaction.guild
401+
respond = interaction.response.send_message
402+
else:
403+
ctx = interaction_or_ctx
404+
user = ctx.author
405+
guild = ctx.guild
406+
respond = ctx.reply
407+
408+
if amount <= 0:
409+
msg = "❌ Amount must be positive."
410+
if is_interaction:
411+
await respond(msg, ephemeral=True)
412+
else:
413+
await respond(msg)
414+
return
415+
416+
# Get user's current stock
417+
current_stock = await self.get_user_stock(user.id)
418+
419+
if current_stock < amount:
420+
msg = f"❌ You only have {current_stock} stock to sell!"
421+
if is_interaction:
422+
await respond(msg, ephemeral=True)
423+
else:
424+
await respond(msg)
425+
return
426+
427+
# Calculate sale price (80% of current stock price)
428+
stock_price = int(self.calculate_stock_price() * 0.8)
429+
total_gain = stock_price * amount
430+
431+
# For interactions, defer first
432+
if is_interaction:
433+
await interaction.response.defer()
434+
435+
# Add money to wallet
436+
if not await db.update_wallet(user.id, total_gain, guild.id if guild else None):
437+
msg = "❌ Failed to process sale. Please try again."
438+
if is_interaction:
439+
await interaction.followup.send(msg, ephemeral=True)
440+
else:
441+
await respond(msg)
442+
return
443+
444+
# Remove stock
445+
result = await db.db.users.update_one(
446+
{"_id": str(user.id)},
447+
{"$set": {"bazaar_stock": current_stock - amount}}
448+
)
449+
450+
if result.modified_count == 0:
451+
# Refund if failed
452+
await db.update_wallet(user.id, -total_gain, guild.id if guild else None)
453+
msg = "❌ Failed to remove stock. Transaction cancelled."
454+
if is_interaction:
455+
await interaction.followup.send(msg, ephemeral=True)
456+
else:
457+
await respond(msg)
458+
return
459+
460+
# Get updated user data
461+
new_stock = current_stock - amount
462+
new_discount = self.calculate_discount(new_stock)
463+
new_balance = await db.get_wallet_balance(user.id, guild.id if guild else None)
464+
465+
# Create embed
466+
embed = discord.Embed(
467+
title="✅ Stock Sale Complete",
468+
description=f"You sold **{amount}** bazaar stock!",
469+
color=0x00ff00
470+
)
471+
472+
embed.add_field(
473+
name="Sale Details",
474+
value=f"Price per Stock: **{stock_price}** {self.currency}\n"
475+
f"Total Gain: **{total_gain}** {self.currency}",
476+
inline=False
477+
)
478+
479+
embed.add_field(
480+
name="Your New Holdings",
481+
value=f"Remaining Stock: **{new_stock}**\n"
482+
f"Current Discount: **{new_discount*100:.0f}%**\n"
483+
f"New Balance: **{new_balance}** {self.currency}",
484+
inline=False
485+
)
486+
487+
# Check if they lost secret shop access
488+
if new_stock < self.stock_threshold and current_stock >= self.stock_threshold:
489+
embed.add_field(
490+
name="🔒 Secret Shop Lost",
491+
value=f"You no longer meet the {self.stock_threshold} stock requirement for secret shop access!",
492+
inline=False
493+
)
494+
495+
try:
496+
if hasattr(self, 'last_stock_message') and self.last_stock_message:
497+
# Edit the existing message
498+
if is_interaction:
499+
await self.last_stock_message.edit(embed=embed)
500+
else:
501+
await self.last_stock_message.edit(embed=embed)
502+
else:
503+
# Send new message and store reference
504+
if is_interaction:
505+
msg = await interaction.followup.send(embed=embed)
506+
else:
507+
msg = await respond(embed=embed)
508+
self.last_stock_message = msg
509+
except Exception as e:
510+
self.logger.error(f"Error updating stock sale message: {e}")
511+
# Fallback to sending new message if edit fails
512+
if is_interaction:
513+
await interaction.followup.send(embed=embed)
514+
else:
515+
await respond(embed=embed)
516+
390517
async def handle_bazaar_purchase(self, interaction_or_ctx, item_id: str = None, amount: int = 1):
391518
"""Handle bazaar purchase from either interaction or command"""
392519
is_interaction = isinstance(interaction_or_ctx, discord.Interaction)
@@ -554,7 +681,7 @@ async def handle_bazaar_purchase(self, interaction_or_ctx, item_id: str = None,
554681
else:
555682
await respond(embed=embed)
556683

557-
@commands.command(name="bazaar-stock", aliases=["bstock"])
684+
@commands.command(name="bazaarstock", aliases=["bstock"])
558685
@commands.cooldown(1, 10, commands.BucketType.user)
559686
async def bazaar_stock(self, ctx, amount: int = 1):
560687
"""Buy bazaar stock"""

cogs/economy/Economy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ async def rob(self, ctx, victim: discord.Member):
248248
fine = int((random.random() * 0.3 + 0.1) * victim_bal)
249249

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

253254
stolen = int(victim_bal * random.uniform(0.1, 0.5))

cogs/economy/Gambling.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ async def _run_crash_game(self, ctx, view, bet: int, current_balance: int):
429429
increment = 0.1
430430
crash_point = random.uniform(1.1, 2.0) # Determine crash point first
431431

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

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

483-
await asyncio.sleep(0.5)
483+
await asyncio.sleep(0.75)
484484

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

953953
# Animation sequence
954-
spin_duration = 3 # seconds
954+
spin_duration = 5 # seconds
955955
spin_steps = 10
956956
delay = spin_duration / spin_steps
957957

cogs/economy/Work.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,36 @@ def __init__(self, bot):
2020
@commands.cooldown(1, 60, commands.BucketType.user)
2121
async def work(self, ctx):
2222
"""Work for some money"""
23-
amount = random.randint(50, 200)
23+
amount = random.randint(100, 1800)
2424
await db.update_wallet(ctx.author.id, amount, ctx.guild.id)
25-
await ctx.reply(f"You worked and earned **{amount}** {self.currency}")
25+
responses = [
26+
f"You worked hard and earned **{amount}** {self.currency}!",
27+
f"Great effort! You just made **{amount}** {self.currency}.",
28+
f"Your dedication paid off! You received **{amount}** {self.currency}.",
29+
f"Well done! You've earned **{amount}** {self.currency}.",
30+
f"Awesome work! You've collected **{amount}** {self.currency}.",
31+
f"Success! You gained **{amount}** {self.currency} from your work.",
32+
f"Keep it up! You earned **{amount}** {self.currency}.",
33+
f"Fantastic job! You made **{amount}** {self.currency}.",
34+
f"Your hard work has been rewarded with **{amount}** {self.currency}.",
35+
f"You put in the effort and earned **{amount}** {self.currency}.",
36+
f"Your labor was fruitful! You received **{amount}** {self.currency}.",
37+
f"You've been productive! You earned **{amount}** {self.currency}.",
38+
f"Your work ethic is impressive! You made **{amount}** {self.currency}.",
39+
f"You've shown great diligence! You earned **{amount}** {self.currency}.",
40+
f"Your commitment to work has paid off! You received **{amount}** {self.currency}.",
41+
f"You've been industrious! You earned **{amount}** {self.currency}.",
42+
f"Your efforts have been fruitful! You made **{amount}** {self.currency}.",
43+
f"You've been a hard worker! You earned **{amount}** {self.currency}.",
44+
f"You've shown great perseverance! You received **{amount}** {self.currency}.",
45+
f"You've been diligent! You earned **{amount}** {self.currency}.",
46+
f"You've been a model employee! You made **{amount}** {self.currency}.",
47+
f"You've been a star worker! You earned **{amount}** {self.currency}.",
48+
f"You've been a top performer! You received **{amount}** {self.currency}.",
49+
f"You've been a valuable asset! You earned **{amount}** {self.currency}.",
50+
f"You've been a key contributor! You made **{amount}** {self.currency}.",
51+
]
52+
await ctx.reply(random.choice(responses))
2653

2754

2855
async def setup(bot):

dashboard/api/index.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

dashboard/api/lastfm_callback.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)