Spaces:
Paused
Paused
Update petroll.py
Browse files- petroll.py +87 -12
petroll.py
CHANGED
|
@@ -3,6 +3,7 @@ from discord import app_commands
|
|
| 3 |
import aiohttp
|
| 4 |
import random
|
| 5 |
import time
|
|
|
|
| 6 |
|
| 7 |
from cash import user_cash
|
| 8 |
|
|
@@ -11,6 +12,7 @@ luck_expiration = {}
|
|
| 11 |
luck_opportunities = {}
|
| 12 |
used_luck_opportunities = set()
|
| 13 |
first_luck_claimed = set()
|
|
|
|
| 14 |
|
| 15 |
async def perform_roll(interaction: discord.Interaction):
|
| 16 |
async def fetch_data(url):
|
|
@@ -164,12 +166,95 @@ async def perform_roll(interaction: discord.Interaction):
|
|
| 164 |
view.remove_item(item)
|
| 165 |
break
|
| 166 |
await interaction.message.edit(view=view)
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
increase_luck_button.callback = increase_luck_callback
|
| 169 |
view.add_item(increase_luck_button)
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
return embed, view
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
@app_commands.command(name="petroll", description="Roll for a random pet")
|
| 174 |
async def petroll(interaction: discord.Interaction):
|
| 175 |
await interaction.response.defer()
|
|
@@ -177,7 +262,7 @@ async def petroll(interaction: discord.Interaction):
|
|
| 177 |
if result:
|
| 178 |
await interaction.followup.send(embed=result[0], view=result[1])
|
| 179 |
else:
|
| 180 |
-
await interaction.followup.send("
|
| 181 |
|
| 182 |
@app_commands.command(name="balance", description="Check your current balance")
|
| 183 |
async def balance(interaction: discord.Interaction):
|
|
@@ -237,14 +322,4 @@ async def roll_dice(interaction: discord.Interaction, bet: int):
|
|
| 237 |
new_view = discord.ui.View()
|
| 238 |
new_view.add_item(roll_again_button)
|
| 239 |
|
| 240 |
-
await interaction.response.edit_message(embed=embed, view=
|
| 241 |
-
|
| 242 |
-
roll_button.callback = roll_dice_callback
|
| 243 |
-
|
| 244 |
-
view = discord.ui.View()
|
| 245 |
-
view.add_item(roll_button)
|
| 246 |
-
|
| 247 |
-
if interaction.response.is_done():
|
| 248 |
-
await interaction.followup.send(embed=embed, view=view)
|
| 249 |
-
else:
|
| 250 |
-
await interaction.response.send_message(embed=embed, view=view)
|
|
|
|
| 3 |
import aiohttp
|
| 4 |
import random
|
| 5 |
import time
|
| 6 |
+
import asyncio
|
| 7 |
|
| 8 |
from cash import user_cash
|
| 9 |
|
|
|
|
| 12 |
luck_opportunities = {}
|
| 13 |
used_luck_opportunities = set()
|
| 14 |
first_luck_claimed = set()
|
| 15 |
+
auto_roll_users = set()
|
| 16 |
|
| 17 |
async def perform_roll(interaction: discord.Interaction):
|
| 18 |
async def fetch_data(url):
|
|
|
|
| 166 |
view.remove_item(item)
|
| 167 |
break
|
| 168 |
await interaction.message.edit(view=view)
|
| 169 |
+
|
| 170 |
+
# Schedule the next luck opportunity
|
| 171 |
+
asyncio.create_task(schedule_next_luck_opportunity(interaction, user_id))
|
| 172 |
|
| 173 |
increase_luck_button.callback = increase_luck_callback
|
| 174 |
view.add_item(increase_luck_button)
|
| 175 |
|
| 176 |
+
auto_roll_button = discord.ui.Button(
|
| 177 |
+
style=discord.ButtonStyle.primary if user_id not in auto_roll_users else discord.ButtonStyle.danger,
|
| 178 |
+
label="Auto Roll" if user_id not in auto_roll_users else "Stop Auto Roll",
|
| 179 |
+
custom_id="auto_roll"
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
async def auto_roll_callback(interaction: discord.Interaction):
|
| 183 |
+
if interaction.user.id != user_id:
|
| 184 |
+
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
| 185 |
+
return
|
| 186 |
+
|
| 187 |
+
if user_id in auto_roll_users:
|
| 188 |
+
auto_roll_users.remove(user_id)
|
| 189 |
+
auto_roll_button.style = discord.ButtonStyle.primary
|
| 190 |
+
auto_roll_button.label = "Auto Roll"
|
| 191 |
+
await interaction.response.send_message("Auto roll stopped.", ephemeral=True)
|
| 192 |
+
else:
|
| 193 |
+
auto_roll_users.add(user_id)
|
| 194 |
+
auto_roll_button.style = discord.ButtonStyle.danger
|
| 195 |
+
auto_roll_button.label = "Stop Auto Roll"
|
| 196 |
+
await interaction.response.send_message("Auto roll started.", ephemeral=True)
|
| 197 |
+
asyncio.create_task(auto_roll(interaction))
|
| 198 |
+
|
| 199 |
+
await interaction.message.edit(view=view)
|
| 200 |
+
|
| 201 |
+
auto_roll_button.callback = auto_roll_callback
|
| 202 |
+
view.add_item(auto_roll_button)
|
| 203 |
+
|
| 204 |
return embed, view
|
| 205 |
|
| 206 |
+
async def schedule_next_luck_opportunity(interaction: discord.Interaction, user_id: int):
|
| 207 |
+
await asyncio.sleep(1800) # Wait for 30 minutes
|
| 208 |
+
luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
|
| 209 |
+
increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
|
| 210 |
+
|
| 211 |
+
async def increase_luck_callback(interaction: discord.Interaction):
|
| 212 |
+
if interaction.user.id != user_id:
|
| 213 |
+
await interaction.response.send_message("You cannot use this button.", ephemeral=True)
|
| 214 |
+
return
|
| 215 |
+
|
| 216 |
+
if user_id in used_luck_opportunities and len(used_luck_opportunities[user_id]) >= 4:
|
| 217 |
+
await interaction.response.send_message("You have already used all your luck.", ephemeral=True)
|
| 218 |
+
return
|
| 219 |
+
|
| 220 |
+
current_luck = luck_multipliers.get(user_id, 1)
|
| 221 |
+
new_luck = min(current_luck + 1, 10)
|
| 222 |
+
luck_multipliers[user_id] = new_luck
|
| 223 |
+
luck_expiration[user_id] = time.time() + 1800
|
| 224 |
+
|
| 225 |
+
if user_id not in used_luck_opportunities:
|
| 226 |
+
used_luck_opportunities[user_id] = set()
|
| 227 |
+
used_luck_opportunities[user_id].add(luck_opportunities[user_id])
|
| 228 |
+
|
| 229 |
+
luck_percentage = (new_luck - 1) * 100
|
| 230 |
+
await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
|
| 231 |
+
|
| 232 |
+
view = interaction.message.components[0]
|
| 233 |
+
for item in view.children:
|
| 234 |
+
if item.custom_id == interaction.custom_id:
|
| 235 |
+
view.remove_item(item)
|
| 236 |
+
break
|
| 237 |
+
await interaction.message.edit(view=view)
|
| 238 |
+
|
| 239 |
+
# Schedule the next luck opportunity
|
| 240 |
+
asyncio.create_task(schedule_next_luck_opportunity(interaction, user_id))
|
| 241 |
+
|
| 242 |
+
increase_luck_button.callback = increase_luck_callback
|
| 243 |
+
|
| 244 |
+
view = interaction.message.components[0]
|
| 245 |
+
view.add_item(increase_luck_button)
|
| 246 |
+
await interaction.message.edit(view=view)
|
| 247 |
+
|
| 248 |
+
async def auto_roll(interaction: discord.Interaction):
|
| 249 |
+
user_id = interaction.user.id
|
| 250 |
+
while user_id in auto_roll_users:
|
| 251 |
+
result = await perform_roll(interaction)
|
| 252 |
+
if result:
|
| 253 |
+
await interaction.followup.send(embed=result[0], view=result[1])
|
| 254 |
+
else:
|
| 255 |
+
await interaction.followup.send("errer")
|
| 256 |
+
await asyncio.sleep(5) # Wait for 5 seconds between rolls
|
| 257 |
+
|
| 258 |
@app_commands.command(name="petroll", description="Roll for a random pet")
|
| 259 |
async def petroll(interaction: discord.Interaction):
|
| 260 |
await interaction.response.defer()
|
|
|
|
| 262 |
if result:
|
| 263 |
await interaction.followup.send(embed=result[0], view=result[1])
|
| 264 |
else:
|
| 265 |
+
await interaction.followup.send("errer.")
|
| 266 |
|
| 267 |
@app_commands.command(name="balance", description="Check your current balance")
|
| 268 |
async def balance(interaction: discord.Interaction):
|
|
|
|
| 322 |
new_view = discord.ui.View()
|
| 323 |
new_view.add_item(roll_again_button)
|
| 324 |
|
| 325 |
+
await interaction.response.edit_message(embed=embed, view=new_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|