uploaded wrong version of the file like an imbecile
This commit is contained in:
parent
9096363ea6
commit
d7ea68a2b0
2 changed files with 47 additions and 42 deletions
|
@ -6,12 +6,12 @@ import subprocess
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import ast
|
import ast
|
||||||
import requests
|
import requests
|
||||||
|
import importlib.metadata
|
||||||
|
|
||||||
from modules.globalvars import *
|
from modules.globalvars import *
|
||||||
from ping3 import ping
|
from ping3 import ping
|
||||||
|
|
||||||
def check_requirements():
|
def check_requirements():
|
||||||
#making this made me cry
|
|
||||||
STD_LIB_MODULES = {
|
STD_LIB_MODULES = {
|
||||||
"os", "sys", "time", "ast", "asyncio", "re", "subprocess", "json",
|
"os", "sys", "time", "ast", "asyncio", "re", "subprocess", "json",
|
||||||
"datetime", "threading", "math", "logging", "functools", "itertools",
|
"datetime", "threading", "math", "logging", "functools", "itertools",
|
||||||
|
@ -21,64 +21,69 @@ def check_requirements():
|
||||||
}
|
}
|
||||||
PACKAGE_ALIASES = {
|
PACKAGE_ALIASES = {
|
||||||
"discord": "discord.py",
|
"discord": "discord.py",
|
||||||
|
"better_profanity": "better-profanity",
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parent_dir = os.path.dirname(os.path.abspath(__file__))
|
parent_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
requirements_path = os.path.join(parent_dir, '..', 'requirements.txt')
|
requirements_path = os.path.join(parent_dir, '..', 'requirements.txt')
|
||||||
requirements_path = os.path.abspath(requirements_path)
|
requirements_path = os.path.abspath(requirements_path)
|
||||||
|
|
||||||
if not os.path.exists(requirements_path):
|
if not os.path.exists(requirements_path):
|
||||||
print(f"{RED}requirements.txt not found at {requirements_path} was it tampered with?{RESET}")
|
print(f"{RED}requirements.txt not found at {requirements_path} was it tampered with?{RESET}")
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(requirements_path, 'r') as f:
|
with open(requirements_path, 'r') as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
requirements = {
|
requirements = {
|
||||||
line.strip() for line in lines
|
line.strip() for line in lines
|
||||||
if line.strip() and not line.startswith('#')
|
if line.strip() and not line.startswith('#')
|
||||||
}
|
}
|
||||||
cogs_dir = os.path.abspath(os.path.join(parent_dir, '..', 'cogs'))
|
|
||||||
if os.path.isdir(cogs_dir):
|
cogs_dir = os.path.abspath(os.path.join(parent_dir, '..', 'cogs'))
|
||||||
for filename in os.listdir(cogs_dir):
|
if os.path.isdir(cogs_dir):
|
||||||
if filename.endswith('.py'):
|
for filename in os.listdir(cogs_dir):
|
||||||
filepath = os.path.join(cogs_dir, filename)
|
if filename.endswith('.py'):
|
||||||
with open(filepath, 'r', encoding='utf-8') as f:
|
filepath = os.path.join(cogs_dir, filename)
|
||||||
try:
|
with open(filepath, 'r', encoding='utf-8') as f:
|
||||||
tree = ast.parse(f.read(), filename=filename)
|
try:
|
||||||
for node in ast.walk(tree):
|
tree = ast.parse(f.read(), filename=filename)
|
||||||
if isinstance(node, ast.Import):
|
for node in ast.walk(tree):
|
||||||
for alias in node.names:
|
if isinstance(node, ast.Import):
|
||||||
pkg = alias.name.split('.')[0]
|
for alias in node.names:
|
||||||
# ADD FILTER HERE
|
pkg = alias.name.split('.')[0]
|
||||||
if pkg in STD_LIB_MODULES or pkg == 'modules':
|
if pkg in STD_LIB_MODULES or pkg == 'modules':
|
||||||
continue
|
continue
|
||||||
requirements.add(pkg)
|
requirements.add(pkg)
|
||||||
elif isinstance(node, ast.ImportFrom):
|
elif isinstance(node, ast.ImportFrom):
|
||||||
if node.module:
|
if node.module:
|
||||||
pkg = node.module.split('.')[0]
|
pkg = node.module.split('.')[0]
|
||||||
# ADD FILTER HERE
|
if pkg in STD_LIB_MODULES or pkg == 'modules':
|
||||||
if pkg in STD_LIB_MODULES or pkg == 'modules':
|
continue
|
||||||
continue
|
requirements.add(pkg)
|
||||||
requirements.add(pkg)
|
except Exception as e:
|
||||||
except Exception as e:
|
print(f"{YELLOW}Warning: Failed to parse imports from {filename}: {e}{RESET}")
|
||||||
print(f"{YELLOW}Warning: Failed to parse imports from {filename}: {e}{RESET}")
|
else:
|
||||||
else:
|
print(f"{YELLOW}Cogs directory not found at {cogs_dir}, skipping scan.{RESET}")
|
||||||
print(f"{YELLOW}Cogs directory not found at {cogs_dir}, skipping scan.{RESET}")
|
|
||||||
installed_packages = {pkg.key for pkg in pkg_resources.working_set}
|
installed_packages = {dist.metadata['Name'].lower() for dist in importlib.metadata.distributions()}
|
||||||
missing = []
|
missing = []
|
||||||
|
|
||||||
for req in sorted(requirements):
|
for req in sorted(requirements):
|
||||||
if req in STD_LIB_MODULES or req == 'modules':
|
if req in STD_LIB_MODULES or req == 'modules':
|
||||||
print(f"{GREEN}STD LIB / LOCAL{RESET} {req} (skipped check)")
|
print(f"{GREEN}STD LIB / LOCAL{RESET} {req} (skipped check)")
|
||||||
continue
|
continue
|
||||||
check_name = PACKAGE_ALIASES.get(req, req)
|
|
||||||
try:
|
check_name = PACKAGE_ALIASES.get(req, req).lower()
|
||||||
pkg_resources.require(check_name)
|
|
||||||
|
if check_name in installed_packages:
|
||||||
print(f"[{GREEN} OK {RESET}] {check_name}")
|
print(f"[{GREEN} OK {RESET}] {check_name}")
|
||||||
except pkg_resources.DistributionNotFound:
|
else:
|
||||||
print(f"[ {RED}MISSING{RESET} ] {check_name} is not installed")
|
print(f"[ {RED}MISSING{RESET} ] {check_name} is not installed")
|
||||||
missing.append(check_name)
|
missing.append(check_name)
|
||||||
except pkg_resources.VersionConflict as e:
|
|
||||||
print(f"[ {YELLOW}VERSION CONFLICT{RESET} ]{check_name} -> {e.report()}")
|
|
||||||
missing.append(check_name)
|
|
||||||
if missing:
|
if missing:
|
||||||
print("\nMissing or conflicting packages detected:")
|
print("\nMissing packages detected:")
|
||||||
for pkg in missing:
|
for pkg in missing:
|
||||||
print(f" - {pkg}")
|
print(f" - {pkg}")
|
||||||
print(f"Telling goober central at {VERSION_URL}")
|
print(f"Telling goober central at {VERSION_URL}")
|
||||||
|
@ -88,13 +93,14 @@ def check_requirements():
|
||||||
"slash_commands": f"{slash_commands_enabled}\n\n**Error**\nMissing packages have been detected, Failed to start",
|
"slash_commands": f"{slash_commands_enabled}\n\n**Error**\nMissing packages have been detected, Failed to start",
|
||||||
"token": gooberTOKEN
|
"token": gooberTOKEN
|
||||||
}
|
}
|
||||||
# Send ping to server
|
try:
|
||||||
response = requests.post(VERSION_URL+"/ping", json=payload)
|
response = requests.post(VERSION_URL + "/ping", json=payload)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{RED}Failed to contact {VERSION_URL}: {e}{RESET}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print("\nAll requirements are satisfied.")
|
print("\nAll requirements are satisfied.")
|
||||||
|
|
||||||
|
|
||||||
def check_latency():
|
def check_latency():
|
||||||
|
|
||||||
host = "1.1.1.1" # change this to google later
|
host = "1.1.1.1" # change this to google later
|
||||||
|
|
|
@ -6,4 +6,3 @@ psutil
|
||||||
better_profanity
|
better_profanity
|
||||||
python-dotenv
|
python-dotenv
|
||||||
ping3
|
ping3
|
||||||
setuptools
|
|
Loading…
Add table
Add a link
Reference in a new issue