coollsd commited on
Commit
66b91a4
·
verified ·
1 Parent(s): aaf1311

Update database.py

Browse files
Files changed (1) hide show
  1. database.py +8 -6
database.py CHANGED
@@ -4,20 +4,22 @@ import json
4
  from cash import user_cash
5
 
6
  @app_commands.command(name="database", description="database")
7
- @app_commands.describe(action="save or load'")
8
  async def database(interaction: discord.Interaction, action: str):
9
  if action.lower() == "save":
10
  with open("database.txt", "w") as f:
11
  json.dump(user_cash, f)
12
- await interaction.response.send_message("saved to database.txt")
13
  elif action.lower() == "load":
14
  try:
15
  with open("database.txt", "r") as f:
16
  loaded_data = json.load(f)
17
  user_cash.clear()
18
- user_cash.update(loaded_data)
19
- await interaction.response.send_message("Database from database.txt")
20
  except FileNotFoundError:
21
- await interaction.response.send_message("AAAAAAAAAA.")
 
 
22
  else:
23
- await interaction.response.send_message("Use 'save' or 'load'.")
 
4
  from cash import user_cash
5
 
6
  @app_commands.command(name="database", description="database")
7
+ @app_commands.describe(action="'save' or 'load'")
8
  async def database(interaction: discord.Interaction, action: str):
9
  if action.lower() == "save":
10
  with open("database.txt", "w") as f:
11
  json.dump(user_cash, f)
12
+ await interaction.response.send_message("Database saved to database.txt")
13
  elif action.lower() == "load":
14
  try:
15
  with open("database.txt", "r") as f:
16
  loaded_data = json.load(f)
17
  user_cash.clear()
18
+ user_cash.update({int(k): v for k, v in loaded_data.items()})
19
+ await interaction.response.send_message("Database")
20
  except FileNotFoundError:
21
+ await interaction.response.send_message(". '/database save' first to create a database.")
22
+ except json.JSONDecodeError:
23
+ await interaction.response.send_message("ERRRERERER")
24
  else:
25
+ await interaction.response.send_message(" Use 'save' or 'load'.")