From ce977e298197b52a03d84b724c7ae0b81c5cd7d9 Mon Sep 17 00:00:00 2001 From: aeru Date: Sun, 18 Oct 2026 00:50:39 +0200 Subject: [PATCH] =?UTF-8?q?stable2=20(pas=20s=C3=BBre,=20aller,=20en=20pro?= =?UTF-8?q?d!)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 15 ++++++++++++--- .../almteshdotnetping.cpython-313.pyc | Bin 0 -> 1198 bytes other/__pycache__/ikavoidping.cpython-313.pyc | Bin 604 -> 1195 bytes other/__pycache__/snartfrping.cpython-313.pyc | Bin 0 -> 1189 bytes other/almteshdotnetping | 11 ----------- other/almteshdotnetping.py | 14 ++++++++++++++ other/ikavoidping.py | 9 ++++++--- other/snartfrping.py | 14 ++++++++++++++ requirements.txt | 2 +- 9 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 other/__pycache__/almteshdotnetping.cpython-313.pyc create mode 100644 other/__pycache__/snartfrping.cpython-313.pyc delete mode 100644 other/almteshdotnetping create mode 100644 other/almteshdotnetping.py create mode 100644 other/snartfrping.py diff --git a/main.py b/main.py index f98767f..fdc00bb 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,12 @@ import discord -import requests import dotenv +import asyncio from discord import app_commands import psutil import time from other.ikavoidping import get_api_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() TOKEN = dotenv.get_key(".env", "DISCORD_TOKEN") @@ -16,6 +17,7 @@ class Bot(discord.Client): self.startup_timestamp = time.time() async def setup_hook(self): + await asyncio.sleep(1) await self.tree.sync() bot = Bot() @@ -25,20 +27,27 @@ async def on_ready(): @bot.tree.command(name="status", description="Get the bot's current status") 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) memory_info = psutil.virtual_memory() used_memory = memory_info.used total_memory = memory_info.total discord_latency = bot.latency 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( f"CPU Usage: {avg_cpu_usage:.2f}%\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"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"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" ) diff --git a/other/__pycache__/almteshdotnetping.cpython-313.pyc b/other/__pycache__/almteshdotnetping.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..364243606456b85614b93368c5c586f8d60d9866 GIT binary patch literal 1198 zcmb7D%}*0S6o0d`-7a)#i!BHTMc?? z^risy?|sbM*?L!3C*Zj8 z?bW5r1mHbW+JkF>`W^(Upn^)Kz-+F>Br0ceD(wT4E|Vy~#mLEP!HjJetfPvO%H?g% z%8crott_?zH5L)&O`P=?m`{cfMxOs^pZbNKDJjh?DyNObVjfdj%A%3hlndI`LRM1@JENKHYnnD}yr?Y3 zXko>XF!@5NkX>LK<_-+X(pnEuY(WV&yL%q>-tT?TUpl|(?OFHAHLv_MyyhJ#o!#{9 zT=zw4zR1(LbziLJi#^}95$Jm~ac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ping deleted file mode 100644 index 305106c..0000000 --- a/other/almteshdotnetping +++ /dev/null @@ -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 \ No newline at end of file diff --git a/other/almteshdotnetping.py b/other/almteshdotnetping.py new file mode 100644 index 0000000..07f002e --- /dev/null +++ b/other/almteshdotnetping.py @@ -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 \ No newline at end of file diff --git a/other/ikavoidping.py b/other/ikavoidping.py index ad1f5dc..b20fd47 100644 --- a/other/ikavoidping.py +++ b/other/ikavoidping.py @@ -1,11 +1,14 @@ -import requests +import aiohttp import time url = "https://api.ikavoid.fr/" async def get_api_ping(): 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() - ping = (end_time - start_time) * 1000 + ping = (end_time - start_time) * 1000 return ping \ No newline at end of file diff --git a/other/snartfrping.py b/other/snartfrping.py new file mode 100644 index 0000000..ff5f2fb --- /dev/null +++ b/other/snartfrping.py @@ -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 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5b23e73..1a276d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ discord.py -requests +aiohttp psutil \ No newline at end of file