stable2 (pas sûre, aller, en prod!)

This commit is contained in:
Aeru committed 2026-10-18 00:50:39 +02:00
1 parent a797fd0c1c
commit ce977e2981
9 files changed
+47 -18

No files matched your search

+12 -3
View File
@@ -1,11 +1,12 @@
import discord import discord
import requests
import dotenv import dotenv
import asyncio
from discord import app_commands from discord import app_commands
import psutil import psutil
import time import time
from other.ikavoidping import get_api_ping from other.ikavoidping import get_api_ping
from other.almteshdotnetping import get_api_ping as get_almtesh_ping from other.almteshdotnetping import get_api_ping as get_almtesh_ping
from other.snartfrping import get_api_ping as get_snartfr_ping
dotenv.load_dotenv() dotenv.load_dotenv()
TOKEN = dotenv.get_key(".env", "DISCORD_TOKEN") TOKEN = dotenv.get_key(".env", "DISCORD_TOKEN")
@@ -16,6 +17,7 @@ class Bot(discord.Client):
self.startup_timestamp = time.time() self.startup_timestamp = time.time()
async def setup_hook(self): async def setup_hook(self):
await asyncio.sleep(1)
await self.tree.sync() await self.tree.sync()
bot = Bot() bot = Bot()
@@ -25,20 +27,27 @@ async def on_ready():
@bot.tree.command(name="status", description="Get the bot's current status") @bot.tree.command(name="status", description="Get the bot's current status")
async def status(interaction: discord.Interaction): async def status(interaction: discord.Interaction):
cpu_usage = psutil.cpu_percent(interval=1, percpu=True) cpu_usage = await asyncio.to_thread(psutil.cpu_percent, interval=1, percpu=True)
avg_cpu_usage = sum(cpu_usage) / len(cpu_usage) avg_cpu_usage = sum(cpu_usage) / len(cpu_usage)
memory_info = psutil.virtual_memory() memory_info = psutil.virtual_memory()
used_memory = memory_info.used used_memory = memory_info.used
total_memory = memory_info.total total_memory = memory_info.total
discord_latency = bot.latency discord_latency = bot.latency
uptime = time.time() - bot.startup_timestamp uptime = time.time() - bot.startup_timestamp
server_uptime = psutil.boot_time()
ikavoid_ping, almtesh_ping, snartfr_ping = await asyncio.gather(
get_api_ping(), get_almtesh_ping(), get_snartfr_ping()
)
await interaction.response.send_message( await interaction.response.send_message(
f"CPU Usage: {avg_cpu_usage:.2f}%\n" f"CPU Usage: {avg_cpu_usage:.2f}%\n"
f"Per-Core CPU Usage: {', '.join(f'{usage}%' for usage in cpu_usage)}\n" f"Per-Core CPU Usage: {', '.join(f'{usage}%' for usage in cpu_usage)}\n"
f"Memory Usage: {memory_info.percent}% ({used_memory / (1024**2):.2f} MB / {total_memory / (1024**2):.2f} MB)\n" f"Memory Usage: {memory_info.percent}% ({used_memory / (1024**2):.2f} MB / {total_memory / (1024**2):.2f} MB)\n"
f"Bot Latency: {discord_latency*1000:.2f} ms\n" f"Bot Latency: {discord_latency*1000:.2f} ms\n"
f"Uptime: {int(uptime // 86400)}d {int((uptime % 86400) // 3600)}h {int((uptime % 3600) // 60)}m {int(uptime % 60)}s\n" f"Uptime: {int(uptime // 86400)}d {int((uptime % 86400) // 3600)}h {int((uptime % 3600) // 60)}m {int(uptime % 60)}s\n"
f"API Ping: {await get_api_ping():.2f} ms" f"ikavoid.fr API Ping: {ikavoid_ping:.2f} ms\n"
f"almtesh.net Ping: {almtesh_ping:.2f} ms\n"
f"snart.fr Ping: {snartfr_ping:.2f} ms\n"
f"Server Uptime: {int((time.time() - server_uptime) // 86400)}d {int(((time.time() - server_uptime) % 86400) // 3600)}h {int(((time.time() - server_uptime) % 3600) // 60)}m {int((time.time() - server_uptime) % 60)}s"
) )
Binary file not shown.
Binary file not shown.
Binary file not shown.
-11
View File
@@ -1,11 +0,0 @@
import requests
import time
url = "https://almtesh.net/"
async def get_api_ping():
start_time = time.time()
requests.get(url)
end_time = time.time()
ping = (end_time - start_time) * 1000
return ping
+14
View File
@@ -0,0 +1,14 @@
import aiohttp
import time
url = "https://almtesh.net/"
async def get_api_ping():
start_time = time.time()
timeout = aiohttp.ClientTimeout(total=10)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get(url):
pass
end_time = time.time()
ping = (end_time - start_time) * 1000
return ping
+6 -3
View File
@@ -1,11 +1,14 @@
import requests import aiohttp
import time import time
url = "https://api.ikavoid.fr/" url = "https://api.ikavoid.fr/"
async def get_api_ping(): async def get_api_ping():
start_time = time.time() start_time = time.time()
requests.get(url) timeout = aiohttp.ClientTimeout(total=10)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get(url):
pass
end_time = time.time() end_time = time.time()
ping = (end_time - start_time) * 1000 ping = (end_time - start_time) * 1000
return ping return ping
+14
View File
@@ -0,0 +1,14 @@
import aiohttp
import time
url = "https://snart.fr/"
async def get_api_ping():
start_time = time.time()
timeout = aiohttp.ClientTimeout(total=10)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get(url):
pass
end_time = time.time()
ping = (end_time - start_time) * 1000
return ping
+1 -1
View File
@@ -1,3 +1,3 @@
discord.py discord.py
requests aiohttp
psutil psutil