Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import asyncio
|
|
5 |
from fastapi import FastAPI
|
6 |
import uvicorn
|
7 |
import random
|
|
|
8 |
|
9 |
app = FastAPI()
|
10 |
intents = discord.Intents.default()
|
@@ -12,6 +13,9 @@ intents.message_content = True
|
|
12 |
bot = discord.Client(intents=intents)
|
13 |
tree = app_commands.CommandTree(bot)
|
14 |
|
|
|
|
|
|
|
15 |
@app.get("/")
|
16 |
async def read_root():
|
17 |
return {"Hello": "World"}
|
@@ -88,8 +92,11 @@ async def perform_roll(interaction: discord.Interaction):
|
|
88 |
if not pets:
|
89 |
return None
|
90 |
|
|
|
|
|
|
|
91 |
# Calculate total difficulty
|
92 |
-
total_difficulty = sum(1 / pet['configData']['difficulty'] for pet in pets)
|
93 |
|
94 |
# Generate a random number between 0 and total_difficulty
|
95 |
random_value = random.uniform(0, total_difficulty)
|
@@ -97,7 +104,7 @@ async def perform_roll(interaction: discord.Interaction):
|
|
97 |
# Select a pet based on the random value
|
98 |
cumulative_probability = 0
|
99 |
for pet in pets:
|
100 |
-
cumulative_probability += 1 / pet['configData']['difficulty']
|
101 |
if random_value <= cumulative_probability:
|
102 |
rolled_pet = pet
|
103 |
break
|
@@ -121,15 +128,25 @@ async def perform_roll(interaction: discord.Interaction):
|
|
121 |
else:
|
122 |
return f"{difficulty} ({difficulty:,})"
|
123 |
|
124 |
-
embed = discord.Embed(title=f"
|
125 |
embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
|
126 |
embed.add_field(name="difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
|
127 |
embed.add_field(name="category", value=rolled_pet['category'], inline=True)
|
128 |
embed.set_thumbnail(url=thumbnail_url)
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
|
132 |
-
|
133 |
async def roll_again_callback(interaction: discord.Interaction):
|
134 |
await interaction.response.defer()
|
135 |
result = await perform_roll(interaction)
|
@@ -143,6 +160,21 @@ async def perform_roll(interaction: discord.Interaction):
|
|
143 |
view = discord.ui.View()
|
144 |
view.add_item(roll_again_button)
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
return embed, view
|
147 |
|
148 |
@tree.command(name="petroll", description="Roll for a random pet")
|
|
|
5 |
from fastapi import FastAPI
|
6 |
import uvicorn
|
7 |
import random
|
8 |
+
import time
|
9 |
|
10 |
app = FastAPI()
|
11 |
intents = discord.Intents.default()
|
|
|
13 |
bot = discord.Client(intents=intents)
|
14 |
tree = app_commands.CommandTree(bot)
|
15 |
|
16 |
+
luck_multipliers = {}
|
17 |
+
luck_expiration = {}
|
18 |
+
|
19 |
@app.get("/")
|
20 |
async def read_root():
|
21 |
return {"Hello": "World"}
|
|
|
92 |
if not pets:
|
93 |
return None
|
94 |
|
95 |
+
user_id = interaction.user.id
|
96 |
+
luck_multiplier = luck_multipliers.get(user_id, 1)
|
97 |
+
|
98 |
# Calculate total difficulty
|
99 |
+
total_difficulty = sum(1 / (pet['configData']['difficulty'] / luck_multiplier) for pet in pets)
|
100 |
|
101 |
# Generate a random number between 0 and total_difficulty
|
102 |
random_value = random.uniform(0, total_difficulty)
|
|
|
104 |
# Select a pet based on the random value
|
105 |
cumulative_probability = 0
|
106 |
for pet in pets:
|
107 |
+
cumulative_probability += 1 / (pet['configData']['difficulty'] / luck_multiplier)
|
108 |
if random_value <= cumulative_probability:
|
109 |
rolled_pet = pet
|
110 |
break
|
|
|
128 |
else:
|
129 |
return f"{difficulty} ({difficulty:,})"
|
130 |
|
131 |
+
embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
|
132 |
embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
|
133 |
embed.add_field(name="difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
|
134 |
embed.add_field(name="category", value=rolled_pet['category'], inline=True)
|
135 |
embed.set_thumbnail(url=thumbnail_url)
|
136 |
+
|
137 |
+
luck_text = ""
|
138 |
+
if user_id in luck_expiration:
|
139 |
+
remaining_time = int(luck_expiration[user_id] - time.time())
|
140 |
+
if remaining_time > 0:
|
141 |
+
luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left!"
|
142 |
+
else:
|
143 |
+
del luck_multipliers[user_id]
|
144 |
+
del luck_expiration[user_id]
|
145 |
+
|
146 |
+
embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
|
147 |
|
148 |
roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
|
149 |
+
|
150 |
async def roll_again_callback(interaction: discord.Interaction):
|
151 |
await interaction.response.defer()
|
152 |
result = await perform_roll(interaction)
|
|
|
160 |
view = discord.ui.View()
|
161 |
view.add_item(roll_again_button)
|
162 |
|
163 |
+
if random.random() < 0.2:
|
164 |
+
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id="increase_luck")
|
165 |
+
|
166 |
+
async def increase_luck_callback(interaction: discord.Interaction):
|
167 |
+
user_id = interaction.user.id
|
168 |
+
if user_id not in luck_multipliers:
|
169 |
+
luck_multipliers[user_id] = 2
|
170 |
+
luck_expiration[user_id] = time.time() + 1800 # 30 minutes
|
171 |
+
else:
|
172 |
+
luck_multipliers[user_id] *= 10
|
173 |
+
await interaction.response.send_message(f"luck increased to: {luck_multipliers[user_id]}x", ephemeral=True)
|
174 |
+
|
175 |
+
increase_luck_button.callback = increase_luck_callback
|
176 |
+
view.add_item(increase_luck_button)
|
177 |
+
|
178 |
return embed, view
|
179 |
|
180 |
@tree.command(name="petroll", description="Roll for a random pet")
|