From f74b310b471acddd35ae098b939e6442afffe888 Mon Sep 17 00:00:00 2001 From: WhatDidYouExpect <89535984+WhatDidYouExpect@users.noreply.github.com> Date: Fri, 25 Apr 2025 11:57:09 +0200 Subject: [PATCH] auto download vader and punkt_tab instead of making the user download them automatically --- .gitignore | 3 ++- bot.py | 32 ++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 5f9170a..d32c20c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ current_version.txt MEMORY_LOADED memory.json *.pkl -*.json \ No newline at end of file +*.json +venv/ \ No newline at end of file diff --git a/bot.py b/bot.py index 138041e..4a946f1 100644 --- a/bot.py +++ b/bot.py @@ -3,8 +3,6 @@ from discord.ext import commands, tasks from discord import app_commands import json import markovify -import nltk -from nltk.tokenize import word_tokenize import random import os import time @@ -20,15 +18,35 @@ from better_profanity import profanity from config import * import traceback import shutil -from nltk.sentiment.vader import SentimentIntensityAnalyzer +import nltk +from nltk.data import find +from nltk import download -analyzer = SentimentIntensityAnalyzer() print(splashtext) # you can use https://patorjk.com/software/taag/ for 3d text or just remove this entirely +def check_resources(): + resources = { + 'vader_lexicon': 'sentiment/vader_lexicon', + 'punkt_tab': 'tokenizers/punkt', + } + + for resource, path in resources.items(): + try: + find(path) + print(f"{resource} is already installed.") + except LookupError: + print(f"{resource} is not installed. Downloading now...") + download(resource) + + +from nltk.sentiment.vader import SentimentIntensityAnalyzer +from nltk.tokenize import word_tokenize +analyzer = SentimentIntensityAnalyzer() + def download_json(): locales_dir = "locales" - response = requests.get(f"{VERSION_URL}/goob/locales/{LOCALE}.json") + response = requests.get(f"https://raw.githubusercontent.com/gooberinc/goober/refs/heads/main/locales/{LOCALE}.json") if response.status_code == 200: if not os.path.exists(locales_dir): @@ -42,7 +60,7 @@ def download_json(): if not os.path.exists(os.path.join(locales_dir, "en.json")): - response = requests.get(f"{VERSION_URL}/goob/locales/en.json") + response = requests.get(f"https://raw.githubusercontent.com/gooberinc/goober/refs/heads/main/locales/en.json") if response.status_code == 200: with open(os.path.join(locales_dir, "en.json"), "w", encoding="utf-8") as file: file.write(response.text) @@ -223,8 +241,6 @@ def get_file_info(file_path): except Exception as e: return {"error": str(e)} -nltk.download('punkt') - def load_memory(): data = []