coollsd commited on
Commit
7f28b05
·
verified ·
1 Parent(s): 5aca793

Update cash.py

Browse files
Files changed (1) hide show
  1. cash.py +9 -13
cash.py CHANGED
@@ -6,25 +6,21 @@ user_cash = {}
6
  def save_database():
7
  with open("database.txt", "w") as f:
8
  for user_id, cash in user_cash.items():
9
- f.write(f"{user_id} cash ({cash})\n")
10
 
11
  def load_database():
12
  global user_cash
13
  try:
14
  with open("database.txt", "r") as f:
15
- content = f.read()
16
-
17
- if content:
18
- user_cash.clear()
19
- for line in content.split('\n'):
20
- if line:
21
- user_id, cash_info = line.split(' cash ')
22
- cash = int(cash_info.strip('()'))
23
- user_cash[int(user_id)] = cash
24
  except FileNotFoundError:
25
- print("empty database.")
26
 
27
- # Load the database when the module is imported
28
  load_database()
29
 
30
  @app_commands.command(name="cash", description="cash")
@@ -35,7 +31,7 @@ async def cash(interaction: discord.Interaction):
35
  if balance == 0:
36
  user_cash[user_id] = 1000
37
  balance = 1000
38
- message = "you are too poor is here $1000"
39
  else:
40
  message = f"Your current balance is ${balance:.2f}"
41
 
 
6
  def save_database():
7
  with open("database.txt", "w") as f:
8
  for user_id, cash in user_cash.items():
9
+ f.write(f"{user_id} cash({cash})\n")
10
 
11
  def load_database():
12
  global user_cash
13
  try:
14
  with open("database.txt", "r") as f:
15
+ for line in f:
16
+ parts = line.strip().split()
17
+ if len(parts) == 2 and parts[1].startswith("cash(") and parts[1].endswith(")"):
18
+ user_id = int(parts[0])
19
+ cash = int(parts[1][5:-1])
20
+ user_cash[user_id] = cash
 
 
 
21
  except FileNotFoundError:
22
+ print("No database making new")
23
 
 
24
  load_database()
25
 
26
  @app_commands.command(name="cash", description="cash")
 
31
  if balance == 0:
32
  user_cash[user_id] = 1000
33
  balance = 1000
34
+ message = "you are too poor here is $1000"
35
  else:
36
  message = f"Your current balance is ${balance:.2f}"
37