coollsd commited on
Commit
f40a4ac
1 Parent(s): d41192d

Update petroll.py

Browse files
Files changed (1) hide show
  1. petroll.py +41 -8
petroll.py CHANGED
@@ -4,9 +4,12 @@ import aiohttp
4
  import random
5
  import time
6
 
 
 
7
  luck_multipliers = {}
8
  luck_expiration = {}
9
  luck_opportunities = {}
 
10
 
11
  async def perform_roll(interaction: discord.Interaction):
12
  async def fetch_data(url):
@@ -57,9 +60,9 @@ async def perform_roll(interaction: discord.Interaction):
57
  return f"{difficulty} ({difficulty:,})"
58
 
59
  embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
60
- embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
61
- embed.add_field(name="difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
62
- embed.add_field(name="category", value=rolled_pet['category'], inline=True)
63
  embed.set_thumbnail(url=thumbnail_url)
64
 
65
  luck_text = ""
@@ -82,29 +85,53 @@ async def perform_roll(interaction: discord.Interaction):
82
  if result:
83
  await interaction.followup.send(embed=result[0], view=result[1])
84
  else:
85
- await interaction.followup.send("errer.")
86
 
87
  roll_again_button.callback = roll_again_callback
88
 
89
  view = discord.ui.View()
90
  view.add_item(roll_again_button)
91
 
92
- if random.random() < 0.2:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
94
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
95
 
96
  async def increase_luck_callback(interaction: discord.Interaction):
97
  if interaction.user.id != user_id:
98
- await interaction.response.send_message("cannot use", ephemeral=True)
99
  return
100
 
 
 
 
 
101
  current_luck = luck_multipliers.get(user_id, 1)
102
  new_luck = min(current_luck + 1, 10)
103
  luck_multipliers[user_id] = new_luck
104
  luck_expiration[user_id] = time.time() + 1800
 
105
 
106
  luck_percentage = (new_luck - 1) * 100
107
- await interaction.response.send_message(f"luck increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
108
 
109
  for item in view.children:
110
  if item.custom_id == interaction.custom_id:
@@ -124,4 +151,10 @@ async def petroll(interaction: discord.Interaction):
124
  if result:
125
  await interaction.followup.send(embed=result[0], view=result[1])
126
  else:
127
- await interaction.followup.send("errer")
 
 
 
 
 
 
 
4
  import random
5
  import time
6
 
7
+ from cash import user_cash
8
+
9
  luck_multipliers = {}
10
  luck_expiration = {}
11
  luck_opportunities = {}
12
+ used_luck_opportunities = set()
13
 
14
  async def perform_roll(interaction: discord.Interaction):
15
  async def fetch_data(url):
 
60
  return f"{difficulty} ({difficulty:,})"
61
 
62
  embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
63
+ embed.add_field(name="Value", value=f"{rap_value:,} diamonds", inline=True)
64
+ embed.add_field(name="Difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
65
+ embed.add_field(name="Category", value=rolled_pet['category'], inline=True)
66
  embed.set_thumbnail(url=thumbnail_url)
67
 
68
  luck_text = ""
 
85
  if result:
86
  await interaction.followup.send(embed=result[0], view=result[1])
87
  else:
88
+ await interaction.followup.send("An error occurred.")
89
 
90
  roll_again_button.callback = roll_again_callback
91
 
92
  view = discord.ui.View()
93
  view.add_item(roll_again_button)
94
 
95
+ sell_button = discord.ui.Button(style=discord.ButtonStyle.success, label=f"Sell Pet for ${rap_value // 100}", custom_id="sell_pet")
96
+
97
+ async def sell_pet_callback(interaction: discord.Interaction):
98
+ if interaction.user.id != user_id:
99
+ await interaction.response.send_message("You cannot sell this pet.", ephemeral=True)
100
+ return
101
+
102
+ sell_value = rap_value // 100
103
+ user_cash[user_id] = user_cash.get(user_id, 0) + sell_value
104
+ await interaction.response.send_message(f"You sold the pet for ${sell_value}. Your new balance is ${user_cash[user_id]}.", ephemeral=True)
105
+ for item in view.children:
106
+ if item.custom_id == "sell_pet":
107
+ view.remove_item(item)
108
+ break
109
+ await interaction.message.edit(view=view)
110
+
111
+ sell_button.callback = sell_pet_callback
112
+ view.add_item(sell_button)
113
+
114
+ if random.random() < 0.2 and user_id not in used_luck_opportunities:
115
  luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
116
  increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
117
 
118
  async def increase_luck_callback(interaction: discord.Interaction):
119
  if interaction.user.id != user_id:
120
+ await interaction.response.send_message("You cannot use this button.", ephemeral=True)
121
  return
122
 
123
+ if user_id in used_luck_opportunities:
124
+ await interaction.response.send_message("You have already used your luck", ephemeral=True)
125
+ return
126
+
127
  current_luck = luck_multipliers.get(user_id, 1)
128
  new_luck = min(current_luck + 1, 10)
129
  luck_multipliers[user_id] = new_luck
130
  luck_expiration[user_id] = time.time() + 1800
131
+ used_luck_opportunities.add(user_id)
132
 
133
  luck_percentage = (new_luck - 1) * 100
134
+ await interaction.response.send_message(f"Your luck has been increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
135
 
136
  for item in view.children:
137
  if item.custom_id == interaction.custom_id:
 
151
  if result:
152
  await interaction.followup.send(embed=result[0], view=result[1])
153
  else:
154
+ await interaction.followup.send("errer")
155
+
156
+ @app_commands.command(name="balance", description="Check your current balance")
157
+ async def balance(interaction: discord.Interaction):
158
+ user_id = interaction.user.id
159
+ current_balance = user_cash.get(user_id, 0)
160
+ await interaction.response.send_message(f"Your current balance is ${current_balance}.", ephemeral=True)