add modules (not community cogs) n fix resource checking
This commit is contained in:
parent
f74b310b47
commit
c891457121
4 changed files with 59 additions and 0 deletions
13
bot.py
13
bot.py
|
@ -39,6 +39,7 @@ def check_resources():
|
||||||
print(f"{resource} is not installed. Downloading now...")
|
print(f"{resource} is not installed. Downloading now...")
|
||||||
download(resource)
|
download(resource)
|
||||||
|
|
||||||
|
check_resources()
|
||||||
|
|
||||||
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
||||||
from nltk.tokenize import word_tokenize
|
from nltk.tokenize import word_tokenize
|
||||||
|
@ -179,6 +180,17 @@ async def load_cogs_from_folder(bot, folder_name="cogs"):
|
||||||
print(f"{RED}{get_translation(LOCALE, 'cog_fail')} {cog_name} {e}{RESET}")
|
print(f"{RED}{get_translation(LOCALE, 'cog_fail')} {cog_name} {e}{RESET}")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
async def load_modules(bot, folder_name="modules"):
|
||||||
|
for filename in os.listdir(folder_name):
|
||||||
|
if filename.endswith(".py") and not filename.startswith("_"):
|
||||||
|
cog_name = filename[:-3]
|
||||||
|
try:
|
||||||
|
await bot.load_extension(f"{folder_name}.{cog_name}")
|
||||||
|
print(f"{GREEN}{get_translation(LOCALE, 'loaded_cog2')} {cog_name}{RESET}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{RED}{get_translation(LOCALE, 'cog_fail2')} {cog_name} {e}{RESET}")
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
currenthash = ""
|
currenthash = ""
|
||||||
def generate_sha256_of_current_file():
|
def generate_sha256_of_current_file():
|
||||||
global currenthash
|
global currenthash
|
||||||
|
@ -312,6 +324,7 @@ async def on_ready():
|
||||||
else:
|
else:
|
||||||
print(f"{DEBUG}{get_translation(LOCALE, 'folder_exists').format(folder_name=folder_name)}{RESET}")
|
print(f"{DEBUG}{get_translation(LOCALE, 'folder_exists').format(folder_name=folder_name)}{RESET}")
|
||||||
markov_model = train_markov_model(memory)
|
markov_model = train_markov_model(memory)
|
||||||
|
await load_modules(bot)
|
||||||
await load_cogs_from_folder(bot)
|
await load_cogs_from_folder(bot)
|
||||||
global slash_commands_enabled
|
global slash_commands_enabled
|
||||||
print(f"{GREEN}{get_translation(LOCALE, 'logged_in')} {bot.user}{RESET}")
|
print(f"{GREEN}{get_translation(LOCALE, 'logged_in')} {bot.user}{RESET}")
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
"not_found": "is not found!",
|
"not_found": "is not found!",
|
||||||
"version_error": "Unable to fetch version info. Status code",
|
"version_error": "Unable to fetch version info. Status code",
|
||||||
"loaded_cog": "Loaded cog:",
|
"loaded_cog": "Loaded cog:",
|
||||||
|
"loaded_cog2": "Loaded module:",
|
||||||
"cog_fail": "Failed to load cog:",
|
"cog_fail": "Failed to load cog:",
|
||||||
|
"cog_fail2": "Failed to load module:",
|
||||||
"no_model": "No saved Markov model found. Starting from scratch.",
|
"no_model": "No saved Markov model found. Starting from scratch.",
|
||||||
"folder_created": "Folder '{folder_name}' created.",
|
"folder_created": "Folder '{folder_name}' created.",
|
||||||
"folder_exists": "Folder '{folder_name}' already exists. skipping...",
|
"folder_exists": "Folder '{folder_name}' already exists. skipping...",
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
"version_error": "Impossibile recuperare le informazioni sulla versione. Codice di stato",
|
"version_error": "Impossibile recuperare le informazioni sulla versione. Codice di stato",
|
||||||
"loaded_cog": "Cog caricato:",
|
"loaded_cog": "Cog caricato:",
|
||||||
"cog_fail": "Impossibile caricare il cog:",
|
"cog_fail": "Impossibile caricare il cog:",
|
||||||
|
"loaded_cog2": "Module caricato:",
|
||||||
|
"cog_fail2": "Impossibile caricare il module:",
|
||||||
"no_model": "Nessun modello Markov salvato trovato. Iniziamo da zero.",
|
"no_model": "Nessun modello Markov salvato trovato. Iniziamo da zero.",
|
||||||
"folder_created": "Cartella '{folder_name}' creata.",
|
"folder_created": "Cartella '{folder_name}' creata.",
|
||||||
"folder_exists": "La cartella '{folder_name}' esiste già. Saltando...",
|
"folder_exists": "La cartella '{folder_name}' esiste già. Saltando...",
|
||||||
|
|
42
modules/grabtemplate.py
Normal file
42
modules/grabtemplate.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
|
import ast
|
||||||
|
|
||||||
|
def get_version_url(config_file_path):
|
||||||
|
with open(config_file_path, "r") as file:
|
||||||
|
file_content = file.read()
|
||||||
|
tree = ast.parse(file_content)
|
||||||
|
for node in ast.walk(tree):
|
||||||
|
if isinstance(node, ast.Assign):
|
||||||
|
for target in node.targets:
|
||||||
|
if isinstance(target, ast.Name) and target.id == "VERSION_URL":
|
||||||
|
if isinstance(node.value, ast.Str):
|
||||||
|
return node.value.s
|
||||||
|
return None
|
||||||
|
config_file_path = "config.py"
|
||||||
|
VERSION_URL = get_version_url(config_file_path)
|
||||||
|
|
||||||
|
|
||||||
|
class grabTemplate(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
def download_json():
|
||||||
|
response = requests.get(f"{VERSION_URL}/goob/template.json")
|
||||||
|
if response.status_code == 200:
|
||||||
|
if os.path.exists("memory.json"):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
userinput = input("Do you want to download the template json instead of starting from scratch?\n(Y/N)\n")
|
||||||
|
if userinput.lower() == "y":
|
||||||
|
with open("memory.json", "w", encoding="utf-8") as file:
|
||||||
|
file.write(response.text)
|
||||||
|
else:
|
||||||
|
print("Starting from scratch...")
|
||||||
|
elif response.status_code == 404:
|
||||||
|
print("File not found on goober central!!")
|
||||||
|
download_json()
|
||||||
|
async def setup(bot):
|
||||||
|
await bot.add_cog(grabTemplate(bot))
|
Loading…
Add table
Add a link
Reference in a new issue