Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
de46e97
1
Parent(s): 3ea7be7
fix 6
Browse files- logger.py +9 -9
- pydvpl_bot.py +8 -16
logger.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import psutil
|
| 3 |
import httpx
|
| 4 |
-
import datetime
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
@app.get("/")
|
| 9 |
async def read_root():
|
| 10 |
# Get system uptime
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
uptime_days, uptime_hours = divmod(uptime_seconds, 86400)
|
| 14 |
uptime_hours, uptime_minutes = divmod(uptime_hours, 3600)
|
| 15 |
uptime_minutes, uptime_seconds = divmod(uptime_minutes, 60)
|
|
@@ -22,18 +22,18 @@ async def read_root():
|
|
| 22 |
async with httpx.AsyncClient() as client:
|
| 23 |
try:
|
| 24 |
response = await client.get("https://www.discord.com")
|
| 25 |
-
latency_ms = response.elapsed.total_seconds() * 1000
|
| 26 |
except httpx.RequestError:
|
| 27 |
latency_ms = "Error: Unable to connect to discord.com"
|
| 28 |
|
| 29 |
return {
|
| 30 |
"System Uptime": {
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
},
|
| 36 |
"CPU Usage": f"{cpu_percent}%",
|
| 37 |
"Memory Usage": f"{memory_percent}%",
|
| 38 |
-
"Latency to Discord
|
| 39 |
}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import psutil
|
| 3 |
import httpx
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
@app.get("/")
|
| 8 |
async def read_root():
|
| 9 |
# Get system uptime
|
| 10 |
+
uptime_seconds = psutil.boot_time()
|
| 11 |
+
|
| 12 |
+
# Convert uptime to days, hours, minutes, seconds
|
| 13 |
uptime_days, uptime_hours = divmod(uptime_seconds, 86400)
|
| 14 |
uptime_hours, uptime_minutes = divmod(uptime_hours, 3600)
|
| 15 |
uptime_minutes, uptime_seconds = divmod(uptime_minutes, 60)
|
|
|
|
| 22 |
async with httpx.AsyncClient() as client:
|
| 23 |
try:
|
| 24 |
response = await client.get("https://www.discord.com")
|
| 25 |
+
latency_ms = round(response.elapsed.total_seconds() * 1000) # Convert seconds to milliseconds and round
|
| 26 |
except httpx.RequestError:
|
| 27 |
latency_ms = "Error: Unable to connect to discord.com"
|
| 28 |
|
| 29 |
return {
|
| 30 |
"System Uptime": {
|
| 31 |
+
"days": uptime_days,
|
| 32 |
+
"hours": uptime_hours,
|
| 33 |
+
"minutes": uptime_minutes,
|
| 34 |
+
"seconds": uptime_seconds
|
| 35 |
},
|
| 36 |
"CPU Usage": f"{cpu_percent}%",
|
| 37 |
"Memory Usage": f"{memory_percent}%",
|
| 38 |
+
"Latency to Discord": f"{latency_ms} ms"
|
| 39 |
}
|
pydvpl_bot.py
CHANGED
|
@@ -124,8 +124,7 @@ async def compress(ctx):
|
|
| 124 |
|
| 125 |
if not attachments:
|
| 126 |
await ctx.send("No file attached.")
|
| 127 |
-
|
| 128 |
-
await ctx.message.delete()
|
| 129 |
return
|
| 130 |
|
| 131 |
for attachment in attachments:
|
|
@@ -134,22 +133,20 @@ async def compress(ctx):
|
|
| 134 |
# Check if the file is already in .dvpl format, if so, skip it
|
| 135 |
if file_path.endswith(".dvpl"):
|
| 136 |
await ctx.send(f"File {attachment.filename} is already in .dvpl format. Skipping.")
|
| 137 |
-
|
| 138 |
-
await ctx.message.delete()
|
| 139 |
continue
|
| 140 |
|
| 141 |
await attachment.save(file_path)
|
| 142 |
compressed_file_path = await compress_file(file_path)
|
| 143 |
if compressed_file_path:
|
| 144 |
await ctx.send(file=discord.File(compressed_file_path))
|
| 145 |
-
await ctx.send(f"The command `compress` was executed by - {ctx.author.mention}")
|
| 146 |
-
await ctx.message.delete()
|
| 147 |
os.remove(file_path) # Delete the original file
|
| 148 |
os.remove(compressed_file_path) # Delete the compressed file
|
| 149 |
else:
|
| 150 |
await ctx.send("Failed to `compress` compress the file.")
|
| 151 |
-
|
| 152 |
-
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
@bot.command(help="Decompresses attached files.")
|
|
@@ -158,8 +155,6 @@ async def decompress(ctx):
|
|
| 158 |
|
| 159 |
if not attachments:
|
| 160 |
await ctx.send("No file attached.")
|
| 161 |
-
await ctx.send(f"The command `decompress` was executed by - {ctx.author.mention}")
|
| 162 |
-
await ctx.message.delete()
|
| 163 |
return
|
| 164 |
|
| 165 |
for attachment in attachments:
|
|
@@ -168,22 +163,19 @@ async def decompress(ctx):
|
|
| 168 |
# Check if the file is not in .dvpl format, if so, skip it
|
| 169 |
if not file_path.endswith(".dvpl"):
|
| 170 |
await ctx.send(f"File {attachment.filename} is not in .dvpl format. Skipping.")
|
| 171 |
-
await ctx.send(f"The command `decompress` was executed by - {ctx.author.mention}")
|
| 172 |
-
await ctx.message.delete()
|
| 173 |
continue
|
| 174 |
|
| 175 |
await attachment.save(file_path)
|
| 176 |
decompressed_file_path = await decompress_file(file_path)
|
| 177 |
if decompressed_file_path:
|
| 178 |
await ctx.send(file=discord.File(decompressed_file_path))
|
| 179 |
-
await ctx.send(f"The command `decompress` was executed by - {ctx.author.mention}")
|
| 180 |
-
await ctx.message.delete()
|
| 181 |
os.remove(file_path) # Delete the original file
|
| 182 |
os.remove(decompressed_file_path) # Delete the decompressed file
|
| 183 |
else:
|
| 184 |
await ctx.send("Failed to decompress the file.")
|
| 185 |
-
|
| 186 |
-
|
|
|
|
| 187 |
|
| 188 |
|
| 189 |
@bot.command(help="Pings to check bot's latency")
|
|
|
|
| 124 |
|
| 125 |
if not attachments:
|
| 126 |
await ctx.send("No file attached.")
|
| 127 |
+
|
|
|
|
| 128 |
return
|
| 129 |
|
| 130 |
for attachment in attachments:
|
|
|
|
| 133 |
# Check if the file is already in .dvpl format, if so, skip it
|
| 134 |
if file_path.endswith(".dvpl"):
|
| 135 |
await ctx.send(f"File {attachment.filename} is already in .dvpl format. Skipping.")
|
| 136 |
+
|
|
|
|
| 137 |
continue
|
| 138 |
|
| 139 |
await attachment.save(file_path)
|
| 140 |
compressed_file_path = await compress_file(file_path)
|
| 141 |
if compressed_file_path:
|
| 142 |
await ctx.send(file=discord.File(compressed_file_path))
|
|
|
|
|
|
|
| 143 |
os.remove(file_path) # Delete the original file
|
| 144 |
os.remove(compressed_file_path) # Delete the compressed file
|
| 145 |
else:
|
| 146 |
await ctx.send("Failed to `compress` compress the file.")
|
| 147 |
+
|
| 148 |
+
await ctx.send(f"The command `compress` was executed by - {ctx.author.mention}")
|
| 149 |
+
await ctx.message.delete()
|
| 150 |
|
| 151 |
|
| 152 |
@bot.command(help="Decompresses attached files.")
|
|
|
|
| 155 |
|
| 156 |
if not attachments:
|
| 157 |
await ctx.send("No file attached.")
|
|
|
|
|
|
|
| 158 |
return
|
| 159 |
|
| 160 |
for attachment in attachments:
|
|
|
|
| 163 |
# Check if the file is not in .dvpl format, if so, skip it
|
| 164 |
if not file_path.endswith(".dvpl"):
|
| 165 |
await ctx.send(f"File {attachment.filename} is not in .dvpl format. Skipping.")
|
|
|
|
|
|
|
| 166 |
continue
|
| 167 |
|
| 168 |
await attachment.save(file_path)
|
| 169 |
decompressed_file_path = await decompress_file(file_path)
|
| 170 |
if decompressed_file_path:
|
| 171 |
await ctx.send(file=discord.File(decompressed_file_path))
|
|
|
|
|
|
|
| 172 |
os.remove(file_path) # Delete the original file
|
| 173 |
os.remove(decompressed_file_path) # Delete the decompressed file
|
| 174 |
else:
|
| 175 |
await ctx.send("Failed to decompress the file.")
|
| 176 |
+
|
| 177 |
+
await ctx.send(f"The command `decompress` was executed by - {ctx.author.mention}")
|
| 178 |
+
await ctx.message.delete()
|
| 179 |
|
| 180 |
|
| 181 |
@bot.command(help="Pings to check bot's latency")
|