added 3 pictures and some default values to stop type checker errors

i also somewhat cleaned up the codebase and changed a few other things.
This commit is contained in:
Charlie 2025-06-28 16:56:05 -04:00
parent 257d3076dd
commit 48a0cec8bb
15 changed files with 81 additions and 79 deletions

View file

@ -2,34 +2,32 @@ import os
import platform
from dotenv import load_dotenv
import pathlib
env_path = pathlib.Path(__file__).parent.parent / '.env'
load_dotenv(dotenv_path=env_path)
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
DEBUG = "\033[1;30m"
RESET = "\033[0m"
ANSI = "\033["
RED = f"{ANSI}31m"
GREEN = f"{ANSI}32m"
YELLOW = f"{ANSI}33m"
DEBUG = f"{ANSI}1;30m"
RESET = f"{ANSI}0m"
VERSION_URL = "https://goober.expect.ovh"
UPDATE_URL = VERSION_URL+"/latest_version.json"
LOCAL_VERSION_FILE = "current_version.txt"
TOKEN = os.getenv("DISCORD_BOT_TOKEN")
PREFIX = os.getenv("BOT_PREFIX")
hourlyspeak = int(os.getenv("hourlyspeak"))
TOKEN = os.getenv("DISCORD_BOT_TOKEN", "0")
PREFIX = os.getenv("BOT_PREFIX", "g.")
hourlyspeak = int(os.getenv("hourlyspeak", "0"))
PING_LINE = os.getenv("PING_LINE")
random_talk_channel_id1 = int(os.getenv("rnd_talk_channel1"))
LOCALE = os.getenv("locale")
LOCALE = os.getenv("locale", "en")
gooberTOKEN = os.getenv("gooberTOKEN")
random_talk_channel_id2 = int(os.getenv("rnd_talk_channel2"))
cooldown_time = os.getenv("cooldown")
splashtext = os.getenv("splashtext")
ownerid = int(os.getenv("ownerid"))
ownerid = int(os.getenv("ownerid", "0"))
showmemenabled = os.getenv("showmemenabled")
BLACKLISTED_USERS = os.getenv("BLACKLISTED_USERS", "").split(",")
USERTRAIN_ENABLED = os.getenv("USERTRAIN_ENABLED", "true").lower() == "true"
NAME = os.getenv("NAME")
last_random_talk_time = 0
MEMORY_FILE = "memory.json"
DEFAULT_DATASET_FILE = "defaultdataset.json"
MEMORY_LOADED_FILE = "MEMORY_LOADED"

View file

@ -45,6 +45,7 @@ async def gen_image(sentence_size=5, max_attempts=10):
midpoint = len(words)//2
return " ".join(words[:midpoint]), " ".join(words[midpoint:])
coherent_response = "no text generated"
attempt = 0
while attempt < max_attempts:
chosen_image_path = os.path.join(images_folder, random.choice(image_files))
@ -97,8 +98,7 @@ async def gen_image(sentence_size=5, max_attempts=10):
if top_height <= max_text_height and bottom_height <= max_text_height:
# top text
draw_text_with_outline(draw, top_text, (width - (top_bbox[2]-top_bbox[0])) / 2, 0, font)
# bottom text
y_bottom = height - bottom_height
y_bottom = height - bottom_height - int(height * 0.04)
draw_text_with_outline(draw, bottom_text, (width - (bottom_bbox[2]-bottom_bbox[0])) / 2, y_bottom, font)
img.save("output.png")
return

View file

@ -3,13 +3,15 @@ import os
import sys
import subprocess
import ast
import json
# import shutil
psutilavaliable = True
try:
import requests
import psutil
except ImportError:
psutilavaliable = False
print("Missing Requests! and Psutil!")
print("Missing requests and psutil! Please install them using pip: `pip install requests psutil`")
import re
import importlib.metadata
@ -169,33 +171,47 @@ def check_memory():
def check_cpu():
if psutilavaliable == False:
return
print("Measuring CPU usage per core...")
cpu_per_core = psutil.cpu_percent(interval=1, percpu=True)
for idx, core_usage in enumerate(cpu_per_core):
bar_length = int(core_usage / 5)
bar = '' * bar_length + '-' * (20 - bar_length)
if core_usage > 85:
color = RED
elif core_usage > 60:
color = YELLOW
else:
color = GREEN
print(f"Core {idx}: {color}[{bar}] {core_usage:.2f}%{RESET}")
print("Measuring CPU usage per core...")
cpu_per_core = psutil.cpu_percent(interval=1, percpu=True)
for idx, core_usage in enumerate(cpu_per_core):
bar_length = int(core_usage / 5)
bar = '' * bar_length + '-' * (20 - bar_length)
if core_usage > 85:
color = RED
elif core_usage > 60:
color = YELLOW
else:
color = GREEN
print(f"Core {idx}: {color}[{bar}] {core_usage:.2f}%{RESET}")
total_cpu = sum(cpu_per_core) / len(cpu_per_core)
print(f"Total CPU Usage: {total_cpu:.2f}%")
total_cpu = sum(cpu_per_core) / len(cpu_per_core)
print(f"Total CPU Usage: {total_cpu:.2f}%")
if total_cpu > 85:
print(f"{YELLOW}High average CPU usage: {total_cpu:.2f}%{RESET}")
if total_cpu > 95:
print(f"{RED}Really high CPU load! System may throttle or hang.{RESET}")
sys.exit(1)
if total_cpu > 85:
print(f"{YELLOW}High average CPU usage: {total_cpu:.2f}%{RESET}")
if total_cpu > 95:
print(f"{RED}Really high CPU load! System may throttle or hang.{RESET}")
sys.exit(1)
def check_memoryjson():
try:
print(f"Memory file: {os.path.getsize(MEMORY_FILE) / (1024 ** 2):.2f} MB")
if os.path.getsize(MEMORY_FILE) > 1_073_741_824:
print(f"{YELLOW}Memory file is 1GB or higher, consider clearing it to free up space.{RESET}")
# Check for corrupted memory.json file
try:
with open(MEMORY_FILE, 'r', encoding='utf-8') as f:
json.load(f)
except json.JSONDecodeError as e:
print(f"{RED}Memory file is corrupted! JSON decode error: {e}{RESET}")
print(f"{YELLOW}Consider backing up and recreating the memory file.{RESET}")
except UnicodeDecodeError as e:
print(f"{RED}Memory file has encoding issues: {e}{RESET}")
print(f"{YELLOW}Consider backing up and recreating the memory file.{RESET}")
except Exception as e:
print(f"{RED}Error reading memory file: {e}{RESET}")
except FileNotFoundError:
print(f"{YELLOW}Memory file not found.{RESET}")
@ -232,13 +248,18 @@ def presskey2skip(timeout):
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
def start_checks():
print("Running pre-start checks...")
check_requirements()
check_latency()
check_memory()
check_memoryjson()
check_cpu()
print("Continuing in 5 seconds... Press any key to skip.")
presskey2skip(5)
os.system('cls' if os.name == 'nt' else 'clear')
print(splashtext)
print("Running pre-start checks...")
check_requirements()
check_latency()
check_memory()
check_memoryjson()
check_cpu()
print("Continuing in 5 seconds... Press any key to skip.")
presskey2skip(timeout=5)
os.system('cls' if os.name == 'nt' else 'clear')
# i decided to experiment with this instead of the above line but it doesn't work too well so that's why i'm not using it
# print("\n" * (shutil.get_terminal_size(fallback=(80, 24))).lines, end="")
print(splashtext)

View file

@ -1,7 +1,5 @@
import hashlib
from modules.translations import *
from modules.globalvars import *
import traceback
import requests
import subprocess
import sys