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

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ memory.json
memory.json memory.json
venv/ venv/
output.png output.png
.vscode/

BIN
assets/images/crash2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

32
bot.py
View file

@ -3,12 +3,9 @@ import re
import json import json
import time import time
import random import random
import shutil
import traceback import traceback
import subprocess import subprocess
from modules.globalvars import * from modules.globalvars import *
from modules.prestartchecks import start_checks from modules.prestartchecks import start_checks
@ -17,21 +14,16 @@ print(splashtext) # Print splash text (from modules/globalvars.py)
start_checks() start_checks()
import requests import requests
import psutil
import discord import discord
from discord.ext import commands, tasks from discord.ext import commands
from discord import app_commands
from discord import Colour from discord import Colour
import nltk import nltk
from nltk.data import find import nltk.data
from nltk import download
from better_profanity import profanity from better_profanity import profanity
from discord.ext import commands
from discord.ext import commands, tasks
from discord import app_commands
from modules.central import ping_server from modules.central import ping_server
from modules.translations import * from modules.translations import *
@ -54,10 +46,10 @@ def check_resources():
} }
for resource, path in resources.items(): for resource, path in resources.items():
try: try:
find(path) # find is from nltk.data nltk.data.find(path)
print(f"{resource} is already installed.") print(f"{resource} is already installed.")
except LookupError: except Exception:
download(resource) # download is from nltk nltk.download(str(resource))
check_resources() check_resources()
@ -145,12 +137,6 @@ async def on_ready():
print(f"{RED}Permission error while syncing commands: {perm_error}{RESET}") print(f"{RED}Permission error while syncing commands: {perm_error}{RESET}")
print(f"{RED}Make sure the bot has the 'applications.commands' scope and is invited with the correct permissions.{RESET}") print(f"{RED}Make sure the bot has the 'applications.commands' scope and is invited with the correct permissions.{RESET}")
quit() quit()
except Exception as e:
print(f"{RED}{get_translation(LOCALE, 'fail_commands_sync')} {e}{RESET}")
traceback.print_exc()
quit()
print(f"{GREEN}{get_translation(LOCALE, 'started').format(name=NAME)}{RESET}")
except Exception as e: except Exception as e:
print(f"{RED}{get_translation(LOCALE, 'fail_commands_sync')} {e}{RESET}") print(f"{RED}{get_translation(LOCALE, 'fail_commands_sync')} {e}{RESET}")
traceback.print_exc() traceback.print_exc()
@ -161,7 +147,7 @@ async def on_ready():
launched = True launched = True
# Load positive GIF URLs from environment variable # Load positive GIF URLs from environment variable
positive_gifs = os.getenv("POSITIVE_GIFS").split(',') positive_gifs: list[str] = os.getenv("POSITIVE_GIFS", "").split(',')
@bot.event @bot.event
async def on_command_error(ctx, error): async def on_command_error(ctx, error):
@ -295,7 +281,7 @@ async def help(ctx):
# Event: Called on every message # Event: Called on every message
@bot.event @bot.event
async def on_message(message): async def on_message(message):
global memory, markov_model, last_random_talk_time global memory, markov_model
# Ignore bot messages # Ignore bot messages
if message.author.bot: if message.author.bot:
@ -396,7 +382,7 @@ async def stats(ctx):
embed = discord.Embed(title=f"{get_translation(LOCALE, 'command_stats_embed_title')}", description=f"{get_translation(LOCALE, 'command_stats_embed_desc')}", color=Colour(0x000000)) embed = discord.Embed(title=f"{get_translation(LOCALE, 'command_stats_embed_title')}", description=f"{get_translation(LOCALE, 'command_stats_embed_desc')}", color=Colour(0x000000))
embed.add_field(name=f"{get_translation(LOCALE, 'command_stats_embed_field1name')}", value=f"{get_translation(LOCALE, 'command_stats_embed_field1value').format(file_size=file_size, line_count=line_count)}", inline=False) embed.add_field(name=f"{get_translation(LOCALE, 'command_stats_embed_field1name')}", value=f"{get_translation(LOCALE, 'command_stats_embed_field1value').format(file_size=file_size, line_count=line_count)}", inline=False)
embed.add_field(name=f"{get_translation(LOCALE, 'command_stats_embed_field2name')}", value=f"{get_translation(LOCALE, 'command_stats_embed_field2value').format(local_version=local_version, latest_version=latest_version)}", inline=False) embed.add_field(name=f"{get_translation(LOCALE, 'command_stats_embed_field2name')}", value=f"{get_translation(LOCALE, 'command_stats_embed_field2value').format(local_version=local_version, latest_version=latest_version)}", inline=False)
embed.add_field(name=f"{get_translation(LOCALE, 'command_stats_embed_field3name')}", value=f"{get_translation(LOCALE, 'command_stats_embed_field3value').format(NAME=NAME, PREFIX=PREFIX, ownerid=ownerid, cooldown_time=cooldown_time, PING_LINE=PING_LINE, showmemenabled=showmemenabled, USERTRAIN_ENABLED=USERTRAIN_ENABLED, last_random_talk_time=last_random_talk_time, song=song, splashtext=splashtext)}", inline=False) embed.add_field(name=f"{get_translation(LOCALE, 'command_stats_embed_field3name')}", value=f"{get_translation(LOCALE, 'command_stats_embed_field3value').format(NAME=NAME, PREFIX=PREFIX, ownerid=ownerid, cooldown_time=cooldown_time, PING_LINE=PING_LINE, showmemenabled=showmemenabled, USERTRAIN_ENABLED=USERTRAIN_ENABLED, song=song, splashtext=splashtext)}", inline=False)
await send_message(ctx, embed=embed) await send_message(ctx, embed=embed)

View file

@ -2,8 +2,6 @@ DISCORD_BOT_TOKEN=token
BOT_PREFIX="g." BOT_PREFIX="g."
PING_LINE="The Beretta fires fast and won't make you feel any better!" PING_LINE="The Beretta fires fast and won't make you feel any better!"
BLACKLISTED_USERS= BLACKLISTED_USERS=
rnd_talk_channel1=1319593363997589614
rnd_talk_channel2=1318263176134918246
cooldown=10800 cooldown=10800
hourlyspeak=1318263176134918246 hourlyspeak=1318263176134918246
ownerid=542701119948849163 ownerid=542701119948849163
@ -15,7 +13,7 @@ ALIVEPING="true"
AUTOUPDATE="True" AUTOUPDATE="True"
gooberTOKEN= gooberTOKEN=
song="War Without Reason" song="War Without Reason"
POSITIVE_GIFS="https://media.discordapp.net/attachments/821047460151427135/1181371808566493184/jjpQGeno.gif, https://tenor.com/view/chill-guy-my-new-character-gif-2777893510283028272,https://tenor.com/view/goodnight-goodnight-friends-weezer-weezer-goodnight-gif-7322052181075806988" POSITIVE_GIFS="https://tenor.com/view/chill-guy-my-new-character-gif-2777893510283028272, https://tenor.com/view/goodnight-goodnight-friends-weezer-weezer-goodnight-gif-7322052181075806988"
splashtext=" splashtext="
d8b d8b
?88 ?88

View file

@ -77,6 +77,6 @@
"command_stats_embed_field2name": "Version", "command_stats_embed_field2name": "Version",
"command_stats_embed_field2value": "Local: {local_version} \nLatest: {latest_version}", "command_stats_embed_field2value": "Local: {local_version} \nLatest: {latest_version}",
"command_stats_embed_field3name": "Variable Info", "command_stats_embed_field3name": "Variable Info",
"command_stats_embed_field3value": "Name: {NAME} \nPrefix: {PREFIX} \nOwner ID: {ownerid} \nCooldown: {cooldown_time} \nPing line: {PING_LINE} \nMemory Sharing Enabled: {showmemenabled} \nUser Training Enabled: {USERTRAIN_ENABLED} \nLast Random TT: {last_random_talk_time} \nSong: {song} \nSplashtext: ```{splashtext}```" "command_stats_embed_field3value": "Name: {NAME} \nPrefix: {PREFIX} \nOwner ID: {ownerid} \nCooldown: {cooldown_time} \nPing line: {PING_LINE} \nMemory Sharing Enabled: {showmemenabled} \nUser Training Enabled: {USERTRAIN_ENABLED}\nSong: {song} \nSplashtext: ```{splashtext}```"
} }

View file

@ -73,5 +73,5 @@
"command_stats_embed_field2name": "Version", "command_stats_embed_field2name": "Version",
"command_stats_embed_field2value": "Version local: {local_version} \nUltima version: {latest_version}", "command_stats_embed_field2value": "Version local: {local_version} \nUltima version: {latest_version}",
"command_stats_embed_field3name": "informacion sobre las variables", "command_stats_embed_field3name": "informacion sobre las variables",
"command_stats_embed_field3value": "Nombre: {NAME} \nPrefijo: {PREFIX} \nID del propietario: {ownerid} \nTiempo de reutilizacion: {cooldown_time} \nLinea de ping: {PING_LINE} \nCompartir memoria habilitada: {showmemenabled} \nEntrenamiento de usuario habilitado: {USERTRAIN_ENABLED} \nUltima conversacion aleatoria: {last_random_talk_time} \nCancion: {song} \nTexto de bienvenida: ```{splashtext}```" "command_stats_embed_field3value": "Nombre: {NAME} \nPrefijo: {PREFIX} \nID del propietario: {ownerid} \nTiempo de reutilizacion: {cooldown_time} \nLinea de ping: {PING_LINE} \nCompartir memoria habilitada: {showmemenabled} \nEntrenamiento de usuario habilitado: {USERTRAIN_ENABLED} \nCancion: {song} \nTexto de bienvenida: ```{splashtext}```"
} }

View file

@ -73,6 +73,6 @@
"command_stats_embed_field2name": "Versio", "command_stats_embed_field2name": "Versio",
"command_stats_embed_field2value": "Paikallinen: {local_version} \nUusin: {latest_version}", "command_stats_embed_field2value": "Paikallinen: {local_version} \nUusin: {latest_version}",
"command_stats_embed_field3name": "Muuttajainformaatio", "command_stats_embed_field3name": "Muuttajainformaatio",
"command_stats_embed_field3value": "Nimi: {NAME} \nEtuliite: {PREFIX} \nOmistajan ID: {ownerid} \nJäähtymisaika: {cooldown_time} \nPing-linja: {PING_LINE} \nMuistin jako päällä: {showmemenabled} \nOppiminen käyttäjistä: {USERTRAIN_ENABLED} \nViimeisin satunnainen TT: {last_random_talk_time} \nLaulu: {song} \nRoisketeksti: ```{splashtext}```" "command_stats_embed_field3value": "Nimi: {NAME} \nEtuliite: {PREFIX} \nOmistajan ID: {ownerid} \nJäähtymisaika: {cooldown_time} \nPing-linja: {PING_LINE} \nMuistin jako päällä: {showmemenabled} \nOppiminen käyttäjistä: {USERTRAIN_ENABLED}\nLaulu: {song} \nRoisketeksti: ```{splashtext}```"
} }

View file

@ -77,5 +77,5 @@
"command_stats_embed_field2name": "Version", "command_stats_embed_field2name": "Version",
"command_stats_embed_field2value": "Locale : {local_version} \nDernière : {latest_version}", "command_stats_embed_field2value": "Locale : {local_version} \nDernière : {latest_version}",
"command_stats_embed_field3name": "Informations variables", "command_stats_embed_field3name": "Informations variables",
"command_stats_embed_field3value": "Nom : {NAME} \nPréfixe : {PREFIX} \nID du propriétaire : {ownerid} \nTemps de recharge : {cooldown_time} \nLigne de ping : {PING_LINE} \nPartage de mémoire activé : {showmemenabled} \nEntraînement utilisateur activé : {USERTRAIN_ENABLED} \nDernier TT aléatoire : {last_random_talk_time} \nChanson : {song} \nTexte de démarrage : ```{splashtext}```" "command_stats_embed_field3value": "Nom : {NAME} \nPréfixe : {PREFIX} \nID du propriétaire : {ownerid} \nTemps de recharge : {cooldown_time} \nLigne de ping : {PING_LINE} \nPartage de mémoire activé : {showmemenabled} \nEntraînement utilisateur activé : {USERTRAIN_ENABLED} \nChanson : {song} \nTexte de démarrage : ```{splashtext}```"
} }

View file

@ -76,6 +76,6 @@
"command_stats_embed_field2name": "Versione", "command_stats_embed_field2name": "Versione",
"command_stats_embed_field2value": "Locale: {local_version} \nUltima: {latest_version}", "command_stats_embed_field2value": "Locale: {local_version} \nUltima: {latest_version}",
"command_stats_embed_field3name": "Informazioni sulle variabili", "command_stats_embed_field3name": "Informazioni sulle variabili",
"command_stats_embed_field3value": "Nome: {NAME} \nPrefisso: {PREFIX} \nID Proprietario: {ownerid} \nCooldown: {cooldown_time} \nLinea ping: {PING_LINE} \nMemoria Condivisa Abilitata: {showmemenabled} \nAddestramento Utente Abilitato: {USERTRAIN_ENABLED} \nUltima TT Casuale: {last_random_talk_time} \nCanzone: {song} \nSplashtext: ```{splashtext}```" "command_stats_embed_field3value": "Nome: {NAME} \nPrefisso: {PREFIX} \nID Proprietario: {ownerid} \nCooldown: {cooldown_time} \nLinea ping: {PING_LINE} \nMemoria Condivisa Abilitata: {showmemenabled} \nAddestramento Utente Abilitato: {USERTRAIN_ENABLED}\nCanzone: {song} \nSplashtext: ```{splashtext}```"
} }

View file

@ -2,34 +2,32 @@ import os
import platform import platform
from dotenv import load_dotenv from dotenv import load_dotenv
import pathlib import pathlib
env_path = pathlib.Path(__file__).parent.parent / '.env' env_path = pathlib.Path(__file__).parent.parent / '.env'
load_dotenv(dotenv_path=env_path) load_dotenv(dotenv_path=env_path)
ANSI = "\033["
RED = "\033[31m" RED = f"{ANSI}31m"
GREEN = "\033[32m" GREEN = f"{ANSI}32m"
YELLOW = "\033[33m" YELLOW = f"{ANSI}33m"
DEBUG = "\033[1;30m" DEBUG = f"{ANSI}1;30m"
RESET = "\033[0m" RESET = f"{ANSI}0m"
VERSION_URL = "https://goober.expect.ovh" VERSION_URL = "https://goober.expect.ovh"
UPDATE_URL = VERSION_URL+"/latest_version.json" UPDATE_URL = VERSION_URL+"/latest_version.json"
LOCAL_VERSION_FILE = "current_version.txt" LOCAL_VERSION_FILE = "current_version.txt"
TOKEN = os.getenv("DISCORD_BOT_TOKEN") TOKEN = os.getenv("DISCORD_BOT_TOKEN", "0")
PREFIX = os.getenv("BOT_PREFIX") PREFIX = os.getenv("BOT_PREFIX", "g.")
hourlyspeak = int(os.getenv("hourlyspeak")) hourlyspeak = int(os.getenv("hourlyspeak", "0"))
PING_LINE = os.getenv("PING_LINE") PING_LINE = os.getenv("PING_LINE")
random_talk_channel_id1 = int(os.getenv("rnd_talk_channel1")) LOCALE = os.getenv("locale", "en")
LOCALE = os.getenv("locale")
gooberTOKEN = os.getenv("gooberTOKEN") gooberTOKEN = os.getenv("gooberTOKEN")
random_talk_channel_id2 = int(os.getenv("rnd_talk_channel2"))
cooldown_time = os.getenv("cooldown") cooldown_time = os.getenv("cooldown")
splashtext = os.getenv("splashtext") splashtext = os.getenv("splashtext")
ownerid = int(os.getenv("ownerid")) ownerid = int(os.getenv("ownerid", "0"))
showmemenabled = os.getenv("showmemenabled") showmemenabled = os.getenv("showmemenabled")
BLACKLISTED_USERS = os.getenv("BLACKLISTED_USERS", "").split(",") BLACKLISTED_USERS = os.getenv("BLACKLISTED_USERS", "").split(",")
USERTRAIN_ENABLED = os.getenv("USERTRAIN_ENABLED", "true").lower() == "true" USERTRAIN_ENABLED = os.getenv("USERTRAIN_ENABLED", "true").lower() == "true"
NAME = os.getenv("NAME") NAME = os.getenv("NAME")
last_random_talk_time = 0
MEMORY_FILE = "memory.json" MEMORY_FILE = "memory.json"
DEFAULT_DATASET_FILE = "defaultdataset.json" DEFAULT_DATASET_FILE = "defaultdataset.json"
MEMORY_LOADED_FILE = "MEMORY_LOADED" 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 midpoint = len(words)//2
return " ".join(words[:midpoint]), " ".join(words[midpoint:]) return " ".join(words[:midpoint]), " ".join(words[midpoint:])
coherent_response = "no text generated"
attempt = 0 attempt = 0
while attempt < max_attempts: while attempt < max_attempts:
chosen_image_path = os.path.join(images_folder, random.choice(image_files)) 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: if top_height <= max_text_height and bottom_height <= max_text_height:
# top text # top text
draw_text_with_outline(draw, top_text, (width - (top_bbox[2]-top_bbox[0])) / 2, 0, font) draw_text_with_outline(draw, top_text, (width - (top_bbox[2]-top_bbox[0])) / 2, 0, font)
# bottom text y_bottom = height - bottom_height - int(height * 0.04)
y_bottom = height - bottom_height
draw_text_with_outline(draw, bottom_text, (width - (bottom_bbox[2]-bottom_bbox[0])) / 2, y_bottom, font) draw_text_with_outline(draw, bottom_text, (width - (bottom_bbox[2]-bottom_bbox[0])) / 2, y_bottom, font)
img.save("output.png") img.save("output.png")
return return

View file

@ -3,13 +3,15 @@ import os
import sys import sys
import subprocess import subprocess
import ast import ast
import json
# import shutil
psutilavaliable = True psutilavaliable = True
try: try:
import requests import requests
import psutil import psutil
except ImportError: except ImportError:
psutilavaliable = False psutilavaliable = False
print("Missing Requests! and Psutil!") print("Missing requests and psutil! Please install them using pip: `pip install requests psutil`")
import re import re
import importlib.metadata import importlib.metadata
@ -169,33 +171,47 @@ def check_memory():
def check_cpu(): def check_cpu():
if psutilavaliable == False: if psutilavaliable == False:
return return
print("Measuring CPU usage per core...") print("Measuring CPU usage per core...")
cpu_per_core = psutil.cpu_percent(interval=1, percpu=True) cpu_per_core = psutil.cpu_percent(interval=1, percpu=True)
for idx, core_usage in enumerate(cpu_per_core): for idx, core_usage in enumerate(cpu_per_core):
bar_length = int(core_usage / 5) bar_length = int(core_usage / 5)
bar = '' * bar_length + '-' * (20 - bar_length) bar = '' * bar_length + '-' * (20 - bar_length)
if core_usage > 85: if core_usage > 85:
color = RED color = RED
elif core_usage > 60: elif core_usage > 60:
color = YELLOW color = YELLOW
else: else:
color = GREEN color = GREEN
print(f"Core {idx}: {color}[{bar}] {core_usage:.2f}%{RESET}") print(f"Core {idx}: {color}[{bar}] {core_usage:.2f}%{RESET}")
total_cpu = sum(cpu_per_core) / len(cpu_per_core) total_cpu = sum(cpu_per_core) / len(cpu_per_core)
print(f"Total CPU Usage: {total_cpu:.2f}%") print(f"Total CPU Usage: {total_cpu:.2f}%")
if total_cpu > 85: if total_cpu > 85:
print(f"{YELLOW}High average CPU usage: {total_cpu:.2f}%{RESET}") print(f"{YELLOW}High average CPU usage: {total_cpu:.2f}%{RESET}")
if total_cpu > 95: if total_cpu > 95:
print(f"{RED}Really high CPU load! System may throttle or hang.{RESET}") print(f"{RED}Really high CPU load! System may throttle or hang.{RESET}")
sys.exit(1) sys.exit(1)
def check_memoryjson(): def check_memoryjson():
try: try:
print(f"Memory file: {os.path.getsize(MEMORY_FILE) / (1024 ** 2):.2f} MB") print(f"Memory file: {os.path.getsize(MEMORY_FILE) / (1024 ** 2):.2f} MB")
if os.path.getsize(MEMORY_FILE) > 1_073_741_824: 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}") 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: except FileNotFoundError:
print(f"{YELLOW}Memory file not found.{RESET}") print(f"{YELLOW}Memory file not found.{RESET}")
@ -232,13 +248,18 @@ def presskey2skip(timeout):
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
def start_checks(): def start_checks():
print("Running pre-start checks...") print("Running pre-start checks...")
check_requirements() check_requirements()
check_latency() check_latency()
check_memory() check_memory()
check_memoryjson() check_memoryjson()
check_cpu() check_cpu()
print("Continuing in 5 seconds... Press any key to skip.") print("Continuing in 5 seconds... Press any key to skip.")
presskey2skip(5) presskey2skip(timeout=5)
os.system('cls' if os.name == 'nt' else 'clear')
print(splashtext) 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.translations import *
from modules.globalvars import * from modules.globalvars import *
import traceback
import requests import requests
import subprocess import subprocess
import sys import sys