turns out volta was compatible with old versions of goober lul
This commit is contained in:
parent
3621a65481
commit
21b5107dd6
5 changed files with 229 additions and 144 deletions
132
bot.py
132
bot.py
|
@ -20,6 +20,7 @@ from better_profanity import profanity
|
|||
from config import *
|
||||
import traceback
|
||||
import shutil
|
||||
from volta import *
|
||||
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
||||
|
||||
analyzer = SentimentIntensityAnalyzer()
|
||||
|
@ -66,63 +67,6 @@ def load_translations():
|
|||
|
||||
translations = load_translations()
|
||||
|
||||
def get_translation(lang: str, key: str):
|
||||
lang_translations = translations.get(lang, translations["en"])
|
||||
if key not in lang_translations:
|
||||
print(f"{RED}Missing key: {key} in language {lang}{RESET}")
|
||||
return lang_translations.get(key, key)
|
||||
|
||||
|
||||
|
||||
def is_name_available(NAME):
|
||||
if os.getenv("gooberTOKEN"):
|
||||
return
|
||||
try:
|
||||
response = requests.post(f"{VERSION_URL}/check-if-available", json={"name": NAME}, headers={"Content-Type": "application/json"})
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
return data.get("available", False)
|
||||
else:
|
||||
print(f"{get_translation(LOCALE, 'name_check')}", response.json())
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"{get_translation(LOCALE, 'name_check2')}", e)
|
||||
return False
|
||||
|
||||
def register_name(NAME):
|
||||
try:
|
||||
if ALIVEPING == False:
|
||||
return
|
||||
# check if the name is avaliable
|
||||
if not is_name_available(NAME):
|
||||
if os.getenv("gooberTOKEN"):
|
||||
return
|
||||
print(f"{RED}{get_translation(LOCALE, 'name_taken')}{RESET}")
|
||||
quit()
|
||||
|
||||
# if it is register it
|
||||
response = requests.post(f"{VERSION_URL}/register", json={"name": NAME}, headers={"Content-Type": "application/json"})
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
token = data.get("token")
|
||||
|
||||
if not os.getenv("gooberTOKEN"):
|
||||
print(f"{GREEN}{get_translation(LOCALE, 'add_token').format(token=token)} gooberTOKEN=<token>.{RESET}")
|
||||
quit()
|
||||
else:
|
||||
print(f"{GREEN}{RESET}")
|
||||
|
||||
return token
|
||||
else:
|
||||
print(f"{RED}{get_translation(LOCALE, 'token_exists').format()}{RESET}", response.json())
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"{RED}{get_translation(LOCALE, 'registration_error').format()}{RESET}", e)
|
||||
return None
|
||||
|
||||
register_name(NAME)
|
||||
|
||||
def save_markov_model(model, filename='markov_model.pkl'):
|
||||
model_file = f"models/{filename}"
|
||||
|
@ -180,42 +124,7 @@ os.environ['gooberlocal_version'] = local_version
|
|||
|
||||
|
||||
def check_for_update():
|
||||
if ALIVEPING == "false":
|
||||
return
|
||||
global latest_version, local_version
|
||||
|
||||
latest_version_info = get_latest_version_info()
|
||||
if not latest_version_info:
|
||||
print(f"{get_translation(LOCALE, 'fetch_update_fail')}")
|
||||
return None, None
|
||||
|
||||
latest_version = latest_version_info.get("version")
|
||||
os.environ['gooberlatest_version'] = latest_version
|
||||
download_url = latest_version_info.get("download_url")
|
||||
|
||||
if not latest_version or not download_url:
|
||||
print(f"{RED}{get_translation(LOCALE, 'invalid_server')}{RESET}")
|
||||
return None, None
|
||||
|
||||
if local_version == "0.0.0" or None:
|
||||
print(f"{RED}I cant find the local_version variable! Or its been tampered with and its not an interger!{RESET}")
|
||||
return
|
||||
|
||||
generate_sha256_of_current_file()
|
||||
gooberhash = latest_version_info.get("hash")
|
||||
if local_version < latest_version:
|
||||
print(f"{YELLOW}{get_translation(LOCALE, 'new_version').format(latest_version=latest_version, local_version=local_version)}{RESET}")
|
||||
print(f"{YELLOW}{get_translation(LOCALE, 'changelog').format(VERSION_URL=VERSION_URL)}{RESET}")
|
||||
if 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")
|
||||
if gooberhash != currenthash:
|
||||
print(f"{YELLOW}{get_translation(LOCALE, 'modification_warning')}")
|
||||
print(f"{YELLOW}{get_translation(LOCALE, 'reported_version')} {local_version}{RESET}")
|
||||
print(f"{DEBUG}{get_translation(LOCALE, 'current_hash')} {currenthash}{RESET}")
|
||||
|
||||
|
||||
check_for_update()
|
||||
return
|
||||
|
||||
def get_file_info(file_path):
|
||||
try:
|
||||
|
@ -317,7 +226,6 @@ async def on_ready():
|
|||
synced = await bot.tree.sync()
|
||||
print(f"{GREEN}{get_translation(LOCALE, 'synced_commands')} {len(synced)} {get_translation(LOCALE, 'synced_commands2')} {RESET}")
|
||||
slash_commands_enabled = True
|
||||
ping_server()
|
||||
print(f"{GREEN}{get_translation(LOCALE, 'started').format()}{RESET}")
|
||||
except Exception as e:
|
||||
print(f"{RED}{get_translation(LOCALE, 'fail_commands_sync')} {e}{RESET}")
|
||||
|
@ -327,33 +235,7 @@ async def on_ready():
|
|||
return
|
||||
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"{song}"))
|
||||
|
||||
def ping_server():
|
||||
if ALIVEPING == "false":
|
||||
print(f"{YELLOW}{get_translation(LOCALE, 'pinging_disabled')}{RESET}")
|
||||
os.environ['gooberauthenticated'] = 'No'
|
||||
return
|
||||
file_info = get_file_info(MEMORY_FILE)
|
||||
payload = {
|
||||
"name": NAME,
|
||||
"memory_file_info": file_info,
|
||||
"version": local_version,
|
||||
"slash_commands": slash_commands_enabled,
|
||||
"token": gooberTOKEN
|
||||
}
|
||||
try:
|
||||
response = requests.post(VERSION_URL+"/ping", json=payload)
|
||||
if response.status_code == 200:
|
||||
print(f"{GREEN}{get_translation(LOCALE, 'goober_ping_success').format(NAME=NAME)}{RESET}")
|
||||
os.environ['gooberauthenticated'] = 'Yes'
|
||||
else:
|
||||
print(f"{RED}{get_translation(LOCALE, 'goober_ping_fail')} {response.status_code}{RESET}")
|
||||
os.environ['gooberauthenticated'] = 'No'
|
||||
except Exception as e:
|
||||
print(f"{RED}{get_translation(LOCALE, 'goober_ping_fail2')} {str(e)}{RESET}")
|
||||
os.environ['gooberauthenticated'] = 'No'
|
||||
|
||||
|
||||
positive_gifs = os.getenv("POSITIVE_GIFS").split(',')
|
||||
positive_gifs = os.getenv("POSITIVEGIFS").split(',')
|
||||
|
||||
def is_positive(sentence):
|
||||
scores = analyzer.polarity_scores(sentence)
|
||||
|
@ -695,15 +577,9 @@ 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()
|
||||
except Exception as e:
|
||||
pass
|
||||
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)
|
||||
embed.add_field(name=f"{get_translation(LOCALE, 'command_about_embed_field2name')}", value=f"{get_translation(LOCALE, 'command_about_embed_field2value').format(local_version=local_version, latest_version=latest_version)}", inline=False)
|
||||
embed.add_field(name=f"{get_translation(LOCALE, 'command_about_embed_field2name')}", value=f"{get_translation(LOCALE, 'command_about_embed_field2value').format(local_version=local_version, latest_version='I have not been updated with the new version checking!')}", inline=False)
|
||||
|
||||
await send_message(ctx, embed=embed)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue