Spaces:
Paused
Paused
Update cash.py
Browse files
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
|
| 10 |
|
| 11 |
def load_database():
|
| 12 |
global user_cash
|
| 13 |
try:
|
| 14 |
with open("database.txt", "r") as f:
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 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("
|
| 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
|
| 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 |
|