coollsd commited on
Commit
6b076a3
·
verified ·
1 Parent(s): 7ab4e04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -260
app.py CHANGED
@@ -1,11 +1,10 @@
1
  import discord
2
  from discord import app_commands
3
- import aiohttp
4
  import asyncio
5
  from fastapi import FastAPI
6
  import uvicorn
7
- import random
8
- import time
9
 
10
  app = FastAPI()
11
  intents = discord.Intents.default()
@@ -13,267 +12,15 @@ intents.message_content = True
13
  bot = discord.Client(intents=intents)
14
  tree = app_commands.CommandTree(bot)
15
 
16
- luck_multipliers = {}
17
- luck_expiration = {}
18
- luck_opportunities = {}
19
- user_cash = {}
20
-
21
  @app.get("/")
22
  async def read_root():
23
  return {"Hello": "World"}
24
 
25
- @tree.command(name="petsimgo", description="get info on pet on petsgo u")
26
- async def petsimgo(interaction: discord.Interaction, petname: str):
27
- await interaction.response.defer()
28
-
29
- async def fetch_data(url):
30
- async with aiohttp.ClientSession() as session:
31
- async with session.get(url) as response:
32
- if response.status == 200:
33
- return await response.json()
34
- return None
35
-
36
- exists_data = await fetch_data("https://petsgo.biggamesapi.io/api/exists")
37
- rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
38
- collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
39
-
40
- if not exists_data or not rap_data or not collection_data:
41
- await interaction.followup.send("error")
42
- return
43
-
44
- pet_exists = next((pet for pet in exists_data['data'] if pet['configData']['id'].lower() == petname.lower()), None)
45
- pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'].lower() == petname.lower()), None)
46
- pet_info = next((pet for pet in collection_data['data'] if pet['configName'].lower() == petname.lower()), None)
47
-
48
- if not pet_exists or not pet_rap or not pet_info:
49
- await interaction.followup.send(f"Pet '{petname}' not found.")
50
- return
51
-
52
- exists_value = pet_exists['value']
53
- rap_value = pet_rap['value']
54
- thumbnail_id = pet_info['configData']['thumbnail'].split('://')[1]
55
-
56
- thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
57
-
58
- def format_difficulty(difficulty):
59
- if difficulty >= 1_000_000_000:
60
- return f"{difficulty / 1_000_000_000:.1f}B ({difficulty:,})"
61
- elif difficulty >= 1_000_000:
62
- return f"{difficulty / 1_000_000:.1f}M ({difficulty:,})"
63
- elif difficulty >= 1_000:
64
- return f"{difficulty / 1_000:.1f}K ({difficulty:,})"
65
- else:
66
- return f"{difficulty} ({difficulty:,})"
67
-
68
- embed = discord.Embed(title=f"PetsGo: {pet_info['configData']['name']}", color=0x787878)
69
- embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
70
- embed.add_field(name="existing", value=f"{exists_value:,}", inline=True)
71
- embed.add_field(name="difficulty", value=format_difficulty(pet_info['configData']['difficulty']), inline=True)
72
- embed.add_field(name="category", value=pet_info['category'], inline=True)
73
- embed.set_thumbnail(url=thumbnail_url)
74
- embed.set_footer(text="hello everyone can i please get a burrito now")
75
-
76
- await interaction.followup.send(embed=embed)
77
-
78
- async def perform_roll(interaction: discord.Interaction):
79
- async def fetch_data(url):
80
- async with aiohttp.ClientSession() as session:
81
- async with session.get(url) as response:
82
- if response.status == 200:
83
- return await response.json()
84
- return None
85
-
86
- rap_data = await fetch_data("https://petsgo.biggamesapi.io/api/Rap")
87
- collection_data = await fetch_data("https://petsgo.biggamesapi.io/api/collection/Pets")
88
-
89
- if not rap_data or not collection_data:
90
- return None
91
-
92
- pets = [pet for pet in collection_data['data'] if pet['configName'] in [p['configData']['id'] for p in rap_data['data']]]
93
-
94
- if not pets:
95
- return None
96
-
97
- user_id = interaction.user.id
98
- luck_multiplier = luck_multipliers.get(user_id, 1)
99
-
100
- sorted_pets = sorted(pets, key=lambda x: x['configData']['difficulty'])
101
-
102
- max_index = len(sorted_pets) - 1
103
- index = int(max_index * (luck_multiplier - 1) / 9)
104
-
105
- rolled_pet = random.choice(sorted_pets[:index+1])
106
-
107
- pet_rap = next((pet for pet in rap_data['data'] if pet['configData']['id'] == rolled_pet['configName']), None)
108
-
109
- if not pet_rap:
110
- return None
111
-
112
- rap_value = pet_rap['value']
113
- thumbnail_id = rolled_pet['configData']['thumbnail'].split('://')[1]
114
- thumbnail_url = f"https://api.rbxgleaks1.workers.dev/asset/{thumbnail_id}"
115
-
116
- def format_difficulty(difficulty):
117
- if difficulty >= 1_000_000_000:
118
- return f"{difficulty / 1_000_000_000:.1f}B ({difficulty:,})"
119
- elif difficulty >= 1_000_000:
120
- return f"{difficulty / 1_000_000:.1f}M ({difficulty:,})"
121
- elif difficulty >= 1_000:
122
- return f"{difficulty / 1_000:.1f}K ({difficulty:,})"
123
- else:
124
- return f"{difficulty} ({difficulty:,})"
125
-
126
- embed = discord.Embed(title=f"{interaction.user.name} rolled: {rolled_pet['configData']['name']}", color=0x787878)
127
- embed.add_field(name="value", value=f"{rap_value:,} diamonds", inline=True)
128
- embed.add_field(name="difficulty", value=format_difficulty(rolled_pet['configData']['difficulty']), inline=True)
129
- embed.add_field(name="category", value=rolled_pet['category'], inline=True)
130
- embed.set_thumbnail(url=thumbnail_url)
131
-
132
- luck_text = ""
133
- if user_id in luck_expiration:
134
- remaining_time = int(luck_expiration[user_id] - time.time())
135
- if remaining_time > 0:
136
- luck_percentage = (luck_multiplier - 1) * 100
137
- luck_text = f"\nYou have {remaining_time // 60} minutes and {remaining_time % 60} seconds of luck left! ({luck_percentage}% luck)"
138
- else:
139
- del luck_multipliers[user_id]
140
- del luck_expiration[user_id]
141
-
142
- embed.set_footer(text=f"Click 'Roll Again' to roll again!{luck_text}")
143
-
144
- roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
145
-
146
- async def roll_again_callback(interaction: discord.Interaction):
147
- await interaction.response.defer()
148
- result = await perform_roll(interaction)
149
- if result:
150
- await interaction.followup.send(embed=result[0], view=result[1])
151
- else:
152
- await interaction.followup.send("errer.")
153
-
154
- roll_again_button.callback = roll_again_callback
155
-
156
- view = discord.ui.View()
157
- view.add_item(roll_again_button)
158
-
159
- if random.random() < 0.2:
160
- luck_opportunities[user_id] = luck_opportunities.get(user_id, 0) + 1
161
- increase_luck_button = discord.ui.Button(style=discord.ButtonStyle.success, label="Increase Luck", custom_id=f"increase_luck_{luck_opportunities[user_id]}")
162
-
163
- async def increase_luck_callback(interaction: discord.Interaction):
164
- if interaction.user.id != user_id:
165
- await interaction.response.send_message("cannot use", ephemeral=True)
166
- return
167
-
168
- current_luck = luck_multipliers.get(user_id, 1)
169
- new_luck = min(current_luck + 1, 10)
170
- luck_multipliers[user_id] = new_luck
171
- luck_expiration[user_id] = time.time() + 1800
172
-
173
- luck_percentage = (new_luck - 1) * 100
174
- await interaction.response.send_message(f"luck increased to {luck_percentage}% for 30 minutes!", ephemeral=True)
175
-
176
- for item in view.children:
177
- if item.custom_id == interaction.custom_id:
178
- view.remove_item(item)
179
- break
180
- await interaction.message.edit(view=view)
181
-
182
- increase_luck_button.callback = increase_luck_callback
183
- view.add_item(increase_luck_button)
184
-
185
- return embed, view
186
-
187
- @tree.command(name="petroll", description="Roll for a random pet")
188
- async def petroll(interaction: discord.Interaction):
189
- await interaction.response.defer()
190
- result = await perform_roll(interaction)
191
- if result:
192
- await interaction.followup.send(embed=result[0], view=result[1])
193
- else:
194
- await interaction.followup.send("errer")
195
-
196
- @tree.command(name="cash", description="Check your current cash balance or claim free cash")
197
- async def cash(interaction: discord.Interaction):
198
- user_id = interaction.user.id
199
- balance = user_cash.get(user_id, 0)
200
-
201
- if balance == 0:
202
- user_cash[user_id] = 100
203
- balance = 100
204
- message = "You've claimed your free $100! Your current balance is $100.00"
205
- else:
206
- message = f"Your current balance is ${balance:.2f}"
207
-
208
- embed = discord.Embed(title="Cash Balance", description=message, color=0x00ff00)
209
- embed.set_footer(text="Use /dice to bet your cash!")
210
-
211
- await interaction.response.send_message(embed=embed)
212
-
213
- @tree.command(name="dice", description="Roll the dice and bet")
214
- async def dice(interaction: discord.Interaction, bet: int):
215
- user_id = interaction.user.id
216
- balance = user_cash.get(user_id, 0)
217
-
218
- if bet <= 0:
219
- await interaction.response.send_message("Your bet must be greater than 0.")
220
- return
221
-
222
- if bet > balance:
223
- await interaction.response.send_message(f"You don't have enough cash. Your current balance is ${balance:.2f}")
224
- return
225
-
226
- embed = discord.Embed(title="Dice Roll", description=f"{interaction.user.name} is betting ${bet:.2f}", color=0x00ff00)
227
- embed.add_field(name="Current Balance", value=f"${balance:.2f}", inline=False)
228
-
229
- roll_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll the Dice", custom_id="roll_dice")
230
-
231
- async def roll_dice_callback(interaction: discord.Interaction):
232
- nonlocal balance
233
- result = random.choice(["win", "lose"])
234
-
235
- if result == "win":
236
- winnings = bet
237
- balance += winnings
238
- result_text = f"You won ${winnings:.2f}!"
239
- else:
240
- balance -= bet
241
- result_text = f"You lost ${bet:.2f}."
242
-
243
- user_cash[user_id] = balance
244
-
245
- embed.clear_fields()
246
- embed.add_field(name="Result", value=result_text, inline=False)
247
- embed.add_field(name="New Balance", value=f"${balance:.2f}", inline=False)
248
-
249
- roll_again_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="Roll Again", custom_id="roll_again")
250
- roll_again_button.callback = lambda i: dice(i, bet)
251
-
252
- new_view = discord.ui.View()
253
- new_view.add_item(roll_again_button)
254
-
255
- await interaction.response.edit_message(embed=embed, view=new_view)
256
-
257
- roll_button.callback = roll_dice_callback
258
-
259
- view = discord.ui.View()
260
- view.add_item(roll_button)
261
-
262
- await interaction.response.send_message(embed=embed, view=view)
263
-
264
- @tree.command(name="admincash", description="Admin command to add cash to a specific user")
265
- async def admincash(interaction: discord.Interaction, user: discord.User, amount: int):
266
- if interaction.user.id != 696434794174611477:
267
- await interaction.response.send_message("You are not authorized to use this command.", ephemeral=True)
268
- return
269
-
270
- user_cash[user.id] = user_cash.get(user.id, 0) + amount
271
- new_balance = user_cash[user.id]
272
-
273
- embed = discord.Embed(title="Admin Cash Added", description=f"Added ${amount:.2f} to {user.name}'s balance", color=0x00ff00)
274
- embed.add_field(name="New Balance", value=f"${new_balance:.2f}", inline=False)
275
-
276
- await interaction.response.send_message(embed=embed)
277
 
278
  @bot.event
279
  async def on_ready():
 
1
  import discord
2
  from discord import app_commands
 
3
  import asyncio
4
  from fastapi import FastAPI
5
  import uvicorn
6
+
7
+ from commands import petsimgo, petroll, cash, dice, admincash
8
 
9
  app = FastAPI()
10
  intents = discord.Intents.default()
 
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"}
18
 
19
+ tree.add_command(petsimgo.petsimgo)
20
+ tree.add_command(petroll.petroll)
21
+ tree.add_command(cash.cash)
22
+ tree.add_command(dice.dice)
23
+ tree.add_command(admincash.admincash)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  @bot.event
26
  async def on_ready():