Spaces:
Building
Building
Update sportbet.py
Browse files- sportbet.py +4 -22
sportbet.py
CHANGED
@@ -3,28 +3,10 @@ from discord import app_commands
|
|
3 |
import aiohttp
|
4 |
import asyncio
|
5 |
from datetime import datetime, timezone
|
|
|
6 |
|
7 |
-
user_cash = {}
|
8 |
user_bets = {}
|
9 |
|
10 |
-
def save_database():
|
11 |
-
with open("database.txt", "w") as f:
|
12 |
-
for user_id, cash in user_cash.items():
|
13 |
-
f.write(f"{user_id} cash({cash})\n")
|
14 |
-
|
15 |
-
def load_database():
|
16 |
-
global user_cash
|
17 |
-
try:
|
18 |
-
with open("database.txt", "r") as f:
|
19 |
-
for line in f:
|
20 |
-
parts = line.strip().split()
|
21 |
-
if len(parts) == 2 and parts[1].startswith("cash(") and parts[1].endswith(")"):
|
22 |
-
user_id = int(parts[0])
|
23 |
-
cash = int(parts[1][5:-1])
|
24 |
-
user_cash[user_id] = cash
|
25 |
-
except FileNotFoundError:
|
26 |
-
print("No database found. Creating a new one.")
|
27 |
-
|
28 |
load_database()
|
29 |
|
30 |
async def fetch_nhl_scores():
|
@@ -69,7 +51,7 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
69 |
raise ValueError("poor")
|
70 |
|
71 |
user_cash[self.user_id] -= bet_amount
|
72 |
-
save_database()
|
73 |
|
74 |
user = await interaction.client.fetch_user(self.user_id)
|
75 |
embed = discord.Embed(title="Bet Placed", color=0x787878)
|
@@ -110,7 +92,7 @@ class BetModal(discord.ui.Modal, title="Place Your Bet"):
|
|
110 |
if game['teams'][winner]['abbreviation'] == self.team:
|
111 |
winnings = bet_amount * 2
|
112 |
user_cash[self.user_id] += winnings
|
113 |
-
save_database()
|
114 |
await interaction.user.send(f"WOO YOUR TEAM WON you won ${winnings}!")
|
115 |
else:
|
116 |
await interaction.user.send(f"Sorry, your team lost booo!")
|
@@ -183,7 +165,7 @@ async def view_current_bets(interaction: discord.Interaction):
|
|
183 |
bet_index = int(cancel_select.values[0])
|
184 |
cancelled_bet = user_bets[user_id].pop(bet_index)
|
185 |
user_cash[user_id] += cancelled_bet['amount']
|
186 |
-
save_database()
|
187 |
await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded.", ephemeral=True)
|
188 |
|
189 |
cancel_select.callback = cancel_callback
|
|
|
3 |
import aiohttp
|
4 |
import asyncio
|
5 |
from datetime import datetime, timezone
|
6 |
+
from cash import user_cash, save_database, load_database
|
7 |
|
|
|
8 |
user_bets = {}
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
load_database()
|
11 |
|
12 |
async def fetch_nhl_scores():
|
|
|
51 |
raise ValueError("poor")
|
52 |
|
53 |
user_cash[self.user_id] -= bet_amount
|
54 |
+
save_database()
|
55 |
|
56 |
user = await interaction.client.fetch_user(self.user_id)
|
57 |
embed = discord.Embed(title="Bet Placed", color=0x787878)
|
|
|
92 |
if game['teams'][winner]['abbreviation'] == self.team:
|
93 |
winnings = bet_amount * 2
|
94 |
user_cash[self.user_id] += winnings
|
95 |
+
save_database()
|
96 |
await interaction.user.send(f"WOO YOUR TEAM WON you won ${winnings}!")
|
97 |
else:
|
98 |
await interaction.user.send(f"Sorry, your team lost booo!")
|
|
|
165 |
bet_index = int(cancel_select.values[0])
|
166 |
cancelled_bet = user_bets[user_id].pop(bet_index)
|
167 |
user_cash[user_id] += cancelled_bet['amount']
|
168 |
+
save_database()
|
169 |
await interaction.response.send_message(f"Bet cancelled. ${cancelled_bet['amount']} has been refunded.", ephemeral=True)
|
170 |
|
171 |
cancel_select.callback = cancel_callback
|