fuckass git

This commit is contained in:
WhatDidYouExpect 2025-07-09 15:05:06 +02:00
parent d3f3e64a96
commit ee4f294b36
7 changed files with 52 additions and 89 deletions

27
bot.py
View file

@ -31,13 +31,6 @@ file_handler.setFormatter(GooberFormatter(colors=False))
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.debug("Testing logging")
logger.info("Testing logging")
logger.warning("Testing logging")
logger.error("Testing logging")
logger.critical("Testing logging")
# Print splash text and check for updates
print(splashtext) # Print splash text (from modules/globalvars.py)
start_checks()
@ -204,13 +197,13 @@ async def retrain(ctx: commands.Context) -> None:
for i, data in enumerate(memory):
processed_data += 1
if processed_data % 1000 == 0 or processed_data == data_size:
await send_message(ctx, f"{(_('command_markov_retraining')).format(processed_data=processed_data, data_size=data_size)}", edit=True, message_reference=processing_message_ref)
await send_message(ctx, f"{_('command_markov_retraining').format(processed_data=processed_data, data_size=data_size)}", edit=True, message_reference=processing_message_ref)
global markov_model
markov_model = train_markov_model(memory)
save_markov_model(markov_model)
await send_message(ctx, f"{(_('command_markov_retrain_successful')).format(data_size=data_size)}", edit=True, message_reference=processing_message_ref)
await send_message(ctx, f"{_('command_markov_retrain_successful').format(data_size=data_size)}", edit=True, message_reference=processing_message_ref)
# Command: Generate a sentence using the Markov model
@bot.hybrid_command(description=f"{(_('command_desc_talk'))}")
@ -270,7 +263,7 @@ async def impact(ctx: commands.Context) -> None:
else:
fallback_image: Optional[str] = get_random_asset_image()
if fallback_image is None:
await ctx.reply((_('no_image_available')))
await ctx.reply(_('no_image_available'))
return
temp_input = tempfile.mktemp(suffix=os.path.splitext(fallback_image)[1])
shutil.copy(fallback_image, temp_input)
@ -278,7 +271,7 @@ async def impact(ctx: commands.Context) -> None:
else:
fallback_image = get_random_asset_image()
if fallback_image is None:
await ctx.reply((_('no_image_available')))
await ctx.reply(_('no_image_available'))
return
temp_input = tempfile.mktemp(suffix=os.path.splitext(fallback_image)[1])
shutil.copy(fallback_image, temp_input)
@ -289,7 +282,7 @@ async def impact(ctx: commands.Context) -> None:
if output_path is None or not os.path.isfile(output_path):
if temp_input and os.path.exists(temp_input):
os.remove(temp_input)
await ctx.reply((_('failed_generate_image')))
await ctx.reply(_('failed_generate_image'))
return
await ctx.send(file=discord.File(output_path))
@ -319,7 +312,7 @@ async def demotivator(ctx: commands.Context) -> None:
else:
fallback_image: Optional[str] = get_random_asset_image()
if fallback_image is None:
await ctx.reply((_('no_image_available')))
await ctx.reply(_('no_image_available'))
return
temp_input = tempfile.mktemp(suffix=os.path.splitext(fallback_image)[1])
shutil.copy(fallback_image, temp_input)
@ -327,7 +320,7 @@ async def demotivator(ctx: commands.Context) -> None:
else:
fallback_image = get_random_asset_image()
if fallback_image is None:
await ctx.reply((_('no_image_available')))
await ctx.reply(_('no_image_available'))
return
temp_input = tempfile.mktemp(suffix=os.path.splitext(fallback_image)[1])
shutil.copy(fallback_image, temp_input)
@ -438,11 +431,11 @@ async def block_blacklisted(ctx: commands.Context) -> bool:
try:
if isinstance(ctx, discord.Interaction):
if not ctx.response.is_done():
await ctx.response.send_message((_('blacklisted')), ephemeral=True)
await ctx.response.send_message(_('blacklisted'), ephemeral=True)
else:
await ctx.followup.send((_('blacklisted')), ephemeral=True)
await ctx.followup.send(_('blacklisted'), ephemeral=True)
else:
await ctx.send((_('blacklisted_user')), ephemeral=True)
await ctx.send(_('blacklisted_user'), ephemeral=True)
except:
pass
return False

37
log.txt
View file

@ -1,37 +0,0 @@
[ DEBUG ]: Testing logging  [07/08/25 17:01:45.827] (bot.py:<module>) 
[ INFO ]: Testing logging  [07/08/25 17:01:45.828] (bot.py:<module>) 
[ WARNING ]: Testing logging  [07/08/25 17:01:45.828] (bot.py:<module>) 
[ ERROR ]: Testing logging  [07/08/25 17:01:45.829] (bot.py:<module>) 
[ CRITICAL ]: Testing logging  [07/08/25 17:01:45.829] (bot.py:<module>) 
[ INFO ]: Suoritetaan esikäynnistystarkistuksia...  [07/08/25 17:01:45.830] (prestartchecks.py:start_checks) 
[ INFO ]: Model is installed.  [07/08/25 17:01:45.832] (prestartchecks.py:check_for_model) 
[ INFO ]: OK aiohttp  [07/08/25 17:01:48.091] (prestartchecks.py:check_requirements) 
[ INFO ]: OK better-profanity  [07/08/25 17:01:48.091] (prestartchecks.py:check_requirements) 
[ INFO ]: OK discord.py  [07/08/25 17:01:48.092] (prestartchecks.py:check_requirements) 
[ INFO ]: OK discord.py  [07/08/25 17:01:48.092] (prestartchecks.py:check_requirements) 
[ INFO ]: OK python-dotenv  [07/08/25 17:01:48.093] (prestartchecks.py:check_requirements) 
[ INFO ]: OK markovify  [07/08/25 17:01:48.093] (prestartchecks.py:check_requirements) 
[ INFO ]: OK pillow  [07/08/25 17:01:48.093] (prestartchecks.py:check_requirements) 
[ INFO ]: OK psutil  [07/08/25 17:01:48.094] (prestartchecks.py:check_requirements) 
[ INFO ]: OK python-dotenv  [07/08/25 17:01:48.094] (prestartchecks.py:check_requirements) 
[ INFO ]: OK requests  [07/08/25 17:01:48.095] (prestartchecks.py:check_requirements) 
[ INFO ]: OK spacy  [07/08/25 17:01:48.095] (prestartchecks.py:check_requirements) 
[ INFO ]: OK spacytextblob  [07/08/25 17:01:48.095] (prestartchecks.py:check_requirements) 
[ INFO ]: Kaikki vaatimukset täyttyvät.  [07/08/25 17:01:48.096] (prestartchecks.py:check_requirements) 
[ INFO ]: Ping osoitteeseen 1.1.1.1: 117.0 ms  [07/08/25 17:01:48.240] (prestartchecks.py:check_latency) 
[ INFO ]: Muistin käyttö: 12.796562194824219 Gt / 15.846412658691406 Gt (80.753685205879%)  [07/08/25 17:01:48.248] (prestartchecks.py:check_memory) 
[ INFO ]: Kokonaismuisti: 15.846412658691406 Gt  [07/08/25 17:01:48.249] (prestartchecks.py:check_memory) 
[ INFO ]: Käytetty muisti: 12.796562194824219 Gt  [07/08/25 17:01:48.249] (prestartchecks.py:check_memory) 
[ INFO ]: Muistitiedosto: 0.00022029876708984375 Mt  [07/08/25 17:01:48.250] (prestartchecks.py:check_memoryjson) 
[ INFO ]: Mitataan suorittimen käyttöä ytimittäin...  [07/08/25 17:01:48.250] (prestartchecks.py:check_cpu) 
[ INFO ]: Ydin 0: [██------------------] 14.1%  [07/08/25 17:01:49.251] (prestartchecks.py:check_cpu) 
[ INFO ]: Ydin 1: [█-------------------] 9.4%  [07/08/25 17:01:49.252] (prestartchecks.py:check_cpu) 
[ INFO ]: Ydin 2: [███-----------------] 17.2%  [07/08/25 17:01:49.252] (prestartchecks.py:check_cpu) 
[ INFO ]: Ydin 3: [███-----------------] 18.8%  [07/08/25 17:01:49.253] (prestartchecks.py:check_cpu) 
[ INFO ]: Ydin 4: [███████-------------] 35.4%  [07/08/25 17:01:49.253] (prestartchecks.py:check_cpu) 
[ INFO ]: Ydin 5: [██████--------------] 31.8%  [07/08/25 17:01:49.253] (prestartchecks.py:check_cpu) 
[ INFO ]: Ydin 6: [██████████----------] 54.4%  [07/08/25 17:01:49.254] (prestartchecks.py:check_cpu) 
[ INFO ]: Ydin 7: [███████-------------] 39.1%  [07/08/25 17:01:49.254] (prestartchecks.py:check_cpu) 
[ INFO ]: Kokonaisprosessorin käyttö: 27.525%  [07/08/25 17:01:49.255] (prestartchecks.py:check_cpu) 
[ INFO ]: Jatketaan 5 sekunnin kuluttua... Paina mitä tahansa näppäintä ohittaaksesi.  [07/08/25 17:01:49.255] (prestartchecks.py:start_checks) 
[ ERROR ]: [VOLTA] Missing key: 'markov_model_not_found' in en.json!  [07/08/25 17:01:59.630] (bot.py:<module>) 

View file

@ -3,17 +3,19 @@ import os
import modules.globalvars as gv
from modules.volta.main import _
from modules.markovmemory import get_file_info
import logging
logger = logging.getLogger("goober")
# Ping the server to check if it's alive and send some info
def ping_server():
if gv.ALIVEPING == "false":
# If pinging is disabled, print message and set environment variable
print(f"{gv.YELLOW}{(_('pinging_disabled'))}{gv.RESET}")
print(f"{gv.YELLOW}{(_('pinging_disabled'))}")
os.environ['gooberauthenticated'] = 'No'
return
# Get server alert message
goobres = requests.get(f"{gv.VERSION_URL}/alert")
print(f"{(_('goober_server_alert'))}{goobres.text}")
logger.info(f"{(_('goober_server_alert'))}{goobres.text}")
# Gather file info for payload
file_info = get_file_info(gv.MEMORY_FILE)
payload = {
@ -28,15 +30,15 @@ def ping_server():
response = requests.post(gv.VERSION_URL+"/ping", json=payload)
if response.status_code == 200:
# Success: print message and set environment variable
print(f"{gv.GREEN}{(_('goober_ping_success')).format(NAME=gv.NAME)}{gv.RESET}")
logger.info(f"{(_('goober_ping_success')).format(NAME=gv.NAME)}")
os.environ['gooberauthenticated'] = 'Yes'
else:
# Failure: print error and set environment variable
print(f"{gv.RED}{(_('goober_ping_fail'))} {response.status_code}{gv.RESET}")
logger.error(f"{(_('goober_ping_fail'))} {response.status_code}")
os.environ['gooberauthenticated'] = 'No'
except Exception as e:
# Exception: print error and set environment variable
print(f"{gv.RED}{(_('goober_ping_fail2'))} {str(e)}{gv.RESET}")
logger.error(f"{(_('goober_ping_fail2'))} {str(e)}")
os.environ['gooberauthenticated'] = 'No'
# Check if a given name is available for registration
@ -52,11 +54,11 @@ def is_name_available(NAME):
return data.get("available", False)
else:
# Print error if request failed
print(f"{(_('name_check'))}", response.json())
logger.e(f"{(_('name_check'))}", response.json())
return False
except Exception as e:
# Print exception if request failed
print(f"{(_('name_check2'))}", e)
logger.error(f"{(_('name_check2'))}", e)
return False
# Register a new name with the server
@ -70,7 +72,7 @@ def register_name(NAME):
if os.getenv("gooberTOKEN"):
return
# Name taken: print error and exit
print(f"{gv.RED}{(_('name_taken'))}{gv.RESET}")
logger.critical(f"{(_('name_taken'))}")
quit()
# Register the name
response = requests.post(f"{gv.VERSION_URL}/register", json={"name": NAME}, headers={"Content-Type": "application/json"})
@ -79,18 +81,18 @@ def register_name(NAME):
token = data.get("token")
if not os.getenv("gooberTOKEN"):
# Print instructions to add token and exit
print(f"{gv.GREEN}{(_('add_token')).format(token=token)} gooberTOKEN=<token>.{gv.gv.RESET}")
logger.info(f"{(_('add_token')).format(token=token)} gooberTOKEN=<token>.")
quit()
else:
print(f"{gv.GREEN}{gv.gv.RESET}")
return token
else:
# Print error if registration failed
print(f"{gv.RED}{(_('token_exists')).format()}{gv.RESET}", response.json())
logger.critical(f"{gv.RED}{(_('token_exists')).format()}", response.json())
return None
except Exception as e:
# Print exception if registration failed
print(f"{gv.RED}{(_('registration_error')).format()}{gv.RESET}", e)
logger.critical(f"{gv.RED}{(_('registration_error')).format()}", e)
return None
# Attempt to register the name at module load

View file

@ -41,5 +41,5 @@ latest_version = "0.0.0"
local_version = "2.1.3"
os.environ['gooberlocal_version'] = local_version
REACT = os.getenv("REACT")
beta = False # this makes goober think its a beta version, so it will not update to the latest stable version or run any version checks
beta = True # this makes goober think its a beta version, so it will not update to the latest stable version or run any version checks

View file

@ -4,7 +4,8 @@ import markovify
import pickle
from modules.globalvars import *
from modules.volta.main import _
import logging
logger = logging.getLogger("goober")
# Get file size and line count for a given file path
def get_file_info(file_path):
try:
@ -47,15 +48,15 @@ def train_markov_model(memory, additional_data=None):
def save_markov_model(model, filename='markov_model.pkl'):
with open(filename, 'wb') as f:
pickle.dump(model, f)
print(f"Markov model saved to {filename}.")
logger.info(f"Markov model saved to {filename}.")
# Load the Markov model from a pickle file
def load_markov_model(filename='markov_model.pkl'):
try:
with open(filename, 'rb') as f:
model = pickle.load(f)
print(f"{GREEN}{_('model_loaded')} {filename}.{RESET}")
logger.info(f"{_('model_loaded')} {filename}.{RESET}")
return model
except FileNotFoundError:
print(f"{RED}{filename} {_('not_found')}{RESET}")
logger.error(f"{filename} {_('not_found')}{RESET}")
return None

View file

@ -6,17 +6,20 @@ import spacy
from spacy.tokens import Doc
from spacytextblob.spacytextblob import SpacyTextBlob
import logging
logger = logging.getLogger("goober")
def check_resources():
try:
nlp = spacy.load("en_core_web_sm")
except OSError:
print((_('spacy_model_not_found')))
logging.critical((_('spacy_model_not_found')))
spacy.cli.download("en_core_web_sm")
nlp = spacy.load("en_core_web_sm")
if "spacytextblob" not in nlp.pipe_names:
nlp.add_pipe("spacytextblob")
print((_('spacy_initialized')))
logger.info((_('spacy_initialized')))
check_resources()
@ -28,8 +31,8 @@ def is_positive(sentence):
doc = nlp(sentence)
sentiment_score = doc._.polarity # from spacytextblob
debug_message = f"{DEBUG}{(_('sentence_positivity'))} {sentiment_score}{RESET}"
print(debug_message)
debug_message = f"{(_('sentence_positivity'))} {sentiment_score}{RESET}"
logger.debug(debug_message)
return sentiment_score > 0.6 # had to raise the bar because it kept saying "death to jews" was fine and it kept reacting to them

View file

@ -3,7 +3,8 @@ from modules.globalvars import *
import requests
import subprocess
import sys
import logging
logger = logging.getLogger("goober")
launched = False
# Run a shell command and return its output
@ -27,11 +28,11 @@ def auto_update(branch='main', remote='origin'):
if is_remote_ahead(branch, remote):
print(_( "remote_ahead").format(remote=remote, branch=branch))
pull_result = run_cmd(f'git pull {remote} {branch}')
print(pull_result)
print(_( "please_restart"))
logger.info(pull_result)
logger.info(_( "please_restart"))
sys.exit(0)
else:
print(_( "local_ahead").format(remote=remote, branch=branch))
logger.info(_( "local_ahead").format(remote=remote, branch=branch))
# Fetch the latest version info from the update server
def get_latest_version_info():
@ -40,10 +41,10 @@ def get_latest_version_info():
if response.status_code == 200:
return response.json()
else:
print(f"{RED}{_( 'version_error')} {response.status_code}{RESET}")
logger.error(f"{RED}{_( 'version_error')} {response.status_code}{RESET}")
return None
except requests.RequestException as e:
print(f"{RED}{_( 'version_error')} {e}{RESET}")
logger.error(f"{RED}{_( 'version_error')} {e}{RESET}")
return None
# Check if an update is available and perform update if needed
@ -54,7 +55,7 @@ def check_for_update():
latest_version_info = get_latest_version_info()
if not latest_version_info:
print(f"{_('fetch_update_fail')}")
logger.error(f"{_('fetch_update_fail')}")
return None, None
latest_version = latest_version_info.get("version")
@ -62,25 +63,25 @@ def check_for_update():
download_url = latest_version_info.get("download_url")
if not latest_version or not download_url:
print(f"{RED}{_(LOCALE, 'invalid_server')}{RESET}")
logger.error(f"{RED}{_(LOCALE, 'invalid_server')}{RESET}")
return None, None
# Check if local_version is valid
if local_version == "0.0.0" or None:
print(f"{RED}{_('cant_find_local_version')}{RESET}")
logger.error(f"{RED}{_('cant_find_local_version')}{RESET}")
return
# Compare local and latest versions
if local_version < latest_version:
print(f"{YELLOW}{_('new_version').format(latest_version=latest_version, local_version=local_version)}{RESET}")
print(f"{YELLOW}{_('changelog').format(VERSION_URL=VERSION_URL)}{RESET}")
logger.info(f"{YELLOW}{_('new_version').format(latest_version=latest_version, local_version=local_version)}{RESET}")
logger.info(f"{YELLOW}{_('changelog').format(VERSION_URL=VERSION_URL)}{RESET}")
auto_update()
elif beta == True:
print(f"{YELLOW}You are running an \"unstable\" version of Goober, do not expect it to work properly.\nVersion {local_version}{RESET}")
logger.warning(f"You are running an \"unstable\" version of Goober, do not expect it to work properly.\nVersion {local_version}{RESET}")
elif local_version > latest_version:
print(f"{YELLOW}{_('modification_warning')}{RESET}")
logger.warning(f"{_('modification_warning')}")
elif local_version == latest_version:
print(f"{GREEN}{_('latest_version')} {local_version}{RESET}")
print(f"{_('latest_version2').format(VERSION_URL=VERSION_URL)}\n\n")
logger.info(f"{_('latest_version')} {local_version}")
logger.info(f"{_('latest_version2').format(VERSION_URL=VERSION_URL)}\n\n")
launched = True
return latest_version