Spaces:
Paused
Paused
Update database.py
Browse files- database.py +10 -37
database.py
CHANGED
|
@@ -1,42 +1,15 @@
|
|
| 1 |
import discord
|
| 2 |
from discord import app_commands
|
| 3 |
-
from cash import user_cash
|
| 4 |
-
import io
|
| 5 |
|
| 6 |
-
@app_commands.command(name="database", description="
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
if action.lower() == "save":
|
| 10 |
-
with open("database.txt", "w") as f:
|
| 11 |
-
for user_id, cash in user_cash.items():
|
| 12 |
-
f.write(f"{user_id} cash ({cash})\n")
|
| 13 |
-
await interaction.response.send_message("Database saved")
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
if content:
|
| 21 |
-
user_cash.clear()
|
| 22 |
-
for line in content.split('\n'):
|
| 23 |
-
if line:
|
| 24 |
-
user_id, cash_info = line.split(' cash ')
|
| 25 |
-
cash = int(cash_info.strip('()'))
|
| 26 |
-
user_cash[int(user_id)] = cash
|
| 27 |
-
|
| 28 |
-
# Create a text file with the current database content
|
| 29 |
-
buffer = io.StringIO()
|
| 30 |
-
for user_id, cash in user_cash.items():
|
| 31 |
-
buffer.write(f"{user_id} cash ({cash})\n")
|
| 32 |
-
buffer.seek(0)
|
| 33 |
-
|
| 34 |
-
# Send the file
|
| 35 |
-
file = discord.File(fp=buffer, filename="current_database.txt")
|
| 36 |
-
await interaction.response.send_message("Current database :", file=file)
|
| 37 |
-
else:
|
| 38 |
-
await interaction.response.send_message("The database is empty.")
|
| 39 |
-
except FileNotFoundError:
|
| 40 |
-
await interaction.response.send_message("errer")
|
| 41 |
else:
|
| 42 |
-
await interaction.response.send_message("
|
|
|
|
| 1 |
import discord
|
| 2 |
from discord import app_commands
|
| 3 |
+
from cash import user_cash, save_database
|
|
|
|
| 4 |
|
| 5 |
+
@app_commands.command(name="database", description="database")
|
| 6 |
+
async def database(interaction: discord.Interaction):
|
| 7 |
+
save_database()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
with open("database.txt", "r") as f:
|
| 10 |
+
content = f.read()
|
| 11 |
+
|
| 12 |
+
if content:
|
| 13 |
+
await interaction.response.send_message(f"database :\n```\n{content}\n```")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
else:
|
| 15 |
+
await interaction.response.send_message("The database is empty.")
|