From 23774d31991823c89f855a2324e19385244b8399 Mon Sep 17 00:00:00 2001 From: expect <89535984+WhatDidYouExpect@users.noreply.github.com> Date: Mon, 23 Jun 2025 13:56:23 +0200 Subject: [PATCH] idiot --- bot.py | 10 ++------- modules/globalvars.py | 2 +- modules/prestartchecks.py | 46 +++++++++++++++++++++++++++++++-------- modules/version.py | 1 + requirements.txt | 1 - 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/bot.py b/bot.py index 05c19a2..103f634 100644 --- a/bot.py +++ b/bot.py @@ -350,10 +350,7 @@ async def ping(ctx): @bot.hybrid_command(description=f"{get_translation(LOCALE, 'command_about_desc')}") async def about(ctx): print("-----------------------------------\n\n") - try: - check_for_update() # check_for_update from modules/version.py - except Exception as e: - pass + latest_version = check_for_update() # check_for_update from modules/version.py print("-----------------------------------") embed = discord.Embed(title=f"{get_translation(LOCALE, 'command_about_embed_title')}", description="", color=discord.Color.blue()) embed.add_field(name=f"{get_translation(LOCALE, 'command_about_embed_field1')}", value=f"{NAME}", inline=False) @@ -367,10 +364,7 @@ async def stats(ctx): if ctx.author.id != ownerid: return print("-----------------------------------\n\n") - try: - check_for_update() # check_for_update from modules/version.py - except Exception as e: - pass + latest_version = check_for_update() # check_for_update from modules/version.py print("-----------------------------------") memory_file = 'memory.json' file_size = os.path.getsize(memory_file) diff --git a/modules/globalvars.py b/modules/globalvars.py index 5c6129e..409dcf7 100644 --- a/modules/globalvars.py +++ b/modules/globalvars.py @@ -40,5 +40,5 @@ song = os.getenv("song") arch = platform.machine() slash_commands_enabled = False latest_version = "0.0.0" -local_version = "0.15.6" +local_version = "0.15.7" os.environ['gooberlocal_version'] = local_version diff --git a/modules/prestartchecks.py b/modules/prestartchecks.py index 8b9f093..9e0df14 100644 --- a/modules/prestartchecks.py +++ b/modules/prestartchecks.py @@ -5,10 +5,11 @@ import sys import subprocess import ast import requests +import re import importlib.metadata from modules.globalvars import * -from ping3 import ping + def check_requirements(): STD_LIB_MODULES = { @@ -101,16 +102,43 @@ def check_requirements(): print("\nAll requirements are satisfied.") def check_latency(): - - host = "1.1.1.1" # change this to google later - latency = ping(host) + host = "1.1.1.1" - if latency is not None: - print(f"Ping to {host}: {latency * 1000:.2f} ms") - if latency * 1000 > 300: - print(f"{YELLOW}High latency detected! You may experience delays in response times.{RESET}") + system = platform.system() + if system == "Windows": + cmd = ["ping", "-n", "1", "-w", "1000", host] + latency_pattern = r"Average = (\d+)ms" else: - print("Ping failed.") + cmd = ["ping", "-c", "1", "-W", "1", host] + latency_pattern = r"time[=<]\s*([\d\.]+)\s*ms" + + try: + result = subprocess.run( + cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ) + + if result.returncode == 0: + print(result.stdout) + + # Try to extract latency + match = re.search(latency_pattern, result.stdout) + if match: + latency_ms = float(match.group(1)) + print(f"Ping to {host}: {latency_ms:.2f} ms") + if latency_ms > 300: + print(f"{YELLOW}High latency detected! You may experience delays in response times.{RESET}") + else: + print(f"{YELLOW}Could not parse latency.{RESET}") + + else: + print(result.stderr) + print(f"{RED}Ping to {host} failed.{RESET}") + + except Exception as e: + print(f"{RED}Error running ping: {e}{RESET}") def check_memory(): try: diff --git a/modules/version.py b/modules/version.py index f3dc993..e93ea3f 100644 --- a/modules/version.py +++ b/modules/version.py @@ -75,3 +75,4 @@ def check_for_update(): elif local_version == latest_version: print(f"{GREEN}{get_translation(LOCALE, 'latest_version')} {local_version}{RESET}") print(f"{get_translation(LOCALE, 'latest_version2').format(VERSION_URL=VERSION_URL)}\n\n") + return latest_version \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5bec737..0da8506 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,3 @@ requests psutil better_profanity python-dotenv -ping3 \ No newline at end of file