From 601bb682f7c5f266937da6ecf245ec22fc1be1d2 Mon Sep 17 00:00:00 2001 From: phixxy Date: Mon, 27 May 2024 01:59:03 -0700 Subject: [PATCH 01/76] fixed command name and output --- cogs/saltstraw.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cogs/saltstraw.py b/cogs/saltstraw.py index e124f16..657e24f 100644 --- a/cogs/saltstraw.py +++ b/cogs/saltstraw.py @@ -20,8 +20,9 @@ class SaltStraw(BotBaseCog): self.url = "https://saltandstraw.com/pages/flavors" @commands.command() - async def test(self, ctx): - await self.parse() + async def icecream(self, ctx): + message = await self.parse() + await ctx.send(message) self.logger.info(f"SaltStraw command called by {ctx.author.name}") async def parse(self): @@ -36,8 +37,11 @@ class SaltStraw(BotBaseCog): for item in parent_sets: child_set = item.find_all("div", limit=3) #limit=3 skips everything past each description, i.e. ingredients/allergens flavor_dict[child_set[0].string] = child_set[1].string #grabbing only the title and description + message = "" for item in flavor_dict: print(f"\n{item}:\n{flavor_dict[item]}\n\n") + message += f"\n{item}:\n{flavor_dict[item]}\n\n" + return message async def setup(bot): await bot.add_cog(SaltStraw(bot)) \ No newline at end of file From 995bb08a0af831af8c08034168b3207a250b30f9 Mon Sep 17 00:00:00 2001 From: phixxy Date: Mon, 27 May 2024 02:06:22 -0700 Subject: [PATCH 02/76] update requirements to include bs4 --- cogs/saltstraw.py | 2 +- requirements.txt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cogs/saltstraw.py b/cogs/saltstraw.py index 657e24f..abf80fe 100644 --- a/cogs/saltstraw.py +++ b/cogs/saltstraw.py @@ -40,7 +40,7 @@ class SaltStraw(BotBaseCog): message = "" for item in flavor_dict: print(f"\n{item}:\n{flavor_dict[item]}\n\n") - message += f"\n{item}:\n{flavor_dict[item]}\n\n" + message += f"\n{item}:\n" return message async def setup(bot): diff --git a/requirements.txt b/requirements.txt index 16facb9..c94a3fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ asyncssh psutil aiofiles inky -wakeonlan \ No newline at end of file +wakeonlan +beautifulsoup4 \ No newline at end of file From d94163e246cc569f96fc4270aa344647f84c5d59 Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 18 Jun 2024 10:00:00 -0700 Subject: [PATCH 03/76] the start of the webui stuff --- .env_default | 15 ++++++++++ flask_templates/index.html | 61 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 3 +- sparkytron_webui.py | 24 +++++++++++++++ src/bot.py | 4 +-- src/webui.py | 45 ++++++++++++++++++++++++++++ 6 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 .env_default create mode 100644 flask_templates/index.html create mode 100644 sparkytron_webui.py create mode 100644 src/webui.py diff --git a/.env_default b/.env_default new file mode 100644 index 0000000..c3c92fb --- /dev/null +++ b/.env_default @@ -0,0 +1,15 @@ +discord_token='token' +flask_port='5000' +imgflip_username='username' +imgflip_password='password' +openai.api_key='api_key' +upload_phixxy='False' +ftp_server='www.example.com' +ftp_username='username' +ftp_password='password' +ftp_public_html='/home/debian/www.example.com/' +stable_diffusion_ip='disabled' +stable_diffusion_port='7861' +stable_diffusion_user= +stable_diffusion_password= +eleven_labs='api-key' diff --git a/flask_templates/index.html b/flask_templates/index.html new file mode 100644 index 0000000..66f14f1 --- /dev/null +++ b/flask_templates/index.html @@ -0,0 +1,61 @@ + + + + + + + Input Form + + +

Warning!

+

This information is stored in PLAIN TEXT in a .env file!

+
+ {% for key, value in key_value_pairs.items() %} + + +
+ {% endfor %} + +
+ + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c94a3fc..1312dad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ psutil aiofiles inky wakeonlan -beautifulsoup4 \ No newline at end of file +beautifulsoup4 +Flask[async] \ No newline at end of file diff --git a/sparkytron_webui.py b/sparkytron_webui.py new file mode 100644 index 0000000..cd0552c --- /dev/null +++ b/sparkytron_webui.py @@ -0,0 +1,24 @@ +import asyncio +import discord +import os +import subprocess +from dotenv import load_dotenv +from src.bot import bot +from src.webui import flask_app + + +def run_flask_app(process): + flask_port = os.getenv("flask_port") + if not flask_port: + flask_port = '5000' + flask_app.bot_process = process + flask_app.run(debug=True, use_reloader=False ,host='0.0.0.0', port=flask_port) + +def main(): + load_dotenv() + process = subprocess.Popen(["python", "sparkytron3000.py"]) + run_flask_app(process) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/bot.py b/src/bot.py index 8c00b66..0160b86 100644 --- a/src/bot.py +++ b/src/bot.py @@ -10,7 +10,6 @@ intents.message_content = True bot = commands.Bot(command_prefix='!', intents=intents) logger = src.logger.logger_setup() - async def load_cogs(bot: commands.Bot, cog_path: str) -> None: for cog_file in os.listdir(cog_path): if cog_file[-3:] == '.py': @@ -27,6 +26,7 @@ async def on_ready(): await utils.delete_all_files("tmp/") await load_cogs(bot, 'cogs/') logger.info('We have logged in as {0.user}'.format(bot)) + print("Visit http://localhost:5000 to change config!") except: logger.warning(f"Error in on_ready") @@ -43,4 +43,4 @@ async def on_message(ctx): except discord.ext.commands.errors.CommandNotFound: logger.info("Command not found.") except Exception as e: - logger.warning(f"Error processing commands: {e}") + logger.warning(f"Error processing commands: {e}") \ No newline at end of file diff --git a/src/webui.py b/src/webui.py new file mode 100644 index 0000000..5024349 --- /dev/null +++ b/src/webui.py @@ -0,0 +1,45 @@ +import logging +import os +import subprocess + +from flask import Flask, render_template, request + +logger = logging.getLogger("bot") +flask_app = Flask(__name__, template_folder='../flask_templates') + +def read_env(filename): + if os.path.exists(filename): + with open(filename, 'r') as file: + key_value_pairs = {} + for line in file: + try: + key, value = line.strip().split('=') + key = key.strip() + value = value.strip()[1:-1] + key_value_pairs[key] = value + except: + print("This line isnt a kv pair") + return key_value_pairs + else: + return None + +@flask_app.route('/', methods=['GET', 'POST']) +async def index(): + key_value_pairs = read_env('.env') + if not key_value_pairs: + logger.warn("No .env file found! Copying defaults.") + key_value_pairs = read_env('.env_default') + form_dict = {} + if request.method == 'POST': + if key_value_pairs: + for form_name in key_value_pairs.keys(): + form_dict[form_name] = request.form[form_name] + with open('.env', 'w') as file: + for key, value in form_dict.items(): + file.write(f"{key}='{value}'\n") + print(form_dict) + flask_app.bot_process.terminate() + flask_app.bot_process = subprocess.Popen(["python", "sparkytron3000.py"]) + return 'Your input has been saved! The bot must be restarted for the changes to take effect.' + return render_template('index.html', key_value_pairs = key_value_pairs) + From 5cd502b19c6d324caba93858d0e0936a9b5983e1 Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 18 Jun 2024 22:59:30 -0700 Subject: [PATCH 04/76] webui progress/added alerts --- flask_templates/index.html | 12 ++++++++++++ sparkytron_webui.py | 6 +++++- src/bot.py | 2 +- src/webui.py | 8 +++++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/flask_templates/index.html b/flask_templates/index.html index 66f14f1..ea93c9c 100644 --- a/flask_templates/index.html +++ b/flask_templates/index.html @@ -1,4 +1,6 @@ + + - Input Form + Sparkytron Config + -

Warning!

-

This information is stored in PLAIN TEXT in a .env file!

-
- {% for key, value in key_value_pairs.items() %} - - -
- {% endfor %} - - {% with messages = get_flashed_messages() %} - {% if messages %} - {% for message in messages %} -
- {{ message }} - +
+

Warning!

+

This information is stored in PLAIN TEXT in a .env file!

+ + {% for key, value in key_value_pairs.items() %} +
+ +
+ +
- {% endfor %} - {% endif %} - {% endwith %} - + {% endfor %} + + + + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} + + {% endfor %} + {% endif %} + {% endwith %} + +
\ No newline at end of file From b14debfb37930eea783ccec9ee8b24606364c697 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 19 Jun 2024 20:59:29 -0700 Subject: [PATCH 07/76] Good enough to merge! --- requirements.txt | 3 ++- sparkytron_webui.py | 20 +++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1312dad..6645a76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ aiofiles inky wakeonlan beautifulsoup4 -Flask[async] \ No newline at end of file +Flask[async] +waitress \ No newline at end of file diff --git a/sparkytron_webui.py b/sparkytron_webui.py index 28ef62f..bb75e1e 100644 --- a/sparkytron_webui.py +++ b/sparkytron_webui.py @@ -6,23 +6,21 @@ import sys from dotenv import load_dotenv from src.bot import bot from src.webui import flask_app +from waitress import serve - -def run_flask_app(process): - flask_port = os.getenv("flask_port") - if not flask_port: - flask_port = '5000' +def get_flask_app(process): flask_app.bot_process = process flask_app.secret_key = "woaoaoahaowhawoiahoahhhhhh" - flask_app.run(debug=True, use_reloader=False ,host='0.0.0.0', port=flask_port) - - + return flask_app def main(): load_dotenv() + flask_port = os.getenv("flask_port") + if not flask_port: + flask_port = '5000' process = subprocess.Popen([sys.executable, "sparkytron3000.py"]) - run_flask_app(process) - - + flask_app = get_flask_app(process) + serve(flask_app, host='0.0.0.0', port=flask_port) + if __name__ == "__main__": main() \ No newline at end of file From 7e8e9a69cd6163fe670d81e51e42225bfc664a09 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 17 Jul 2024 23:13:13 -0700 Subject: [PATCH 08/76] added a simple translate command for text files --- cogs/chatgpt.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cogs/chatgpt.py b/cogs/chatgpt.py index 3bf0ed8..da7be40 100644 --- a/cogs/chatgpt.py +++ b/cogs/chatgpt.py @@ -312,6 +312,25 @@ class ChatGPT(commands.Cog): self.logger.exception("Error occurred in answer_question") return "Error occurred in answer_question" + @commands.command() + async def translate(self, ctx): + if ctx.message.attachments: + attachment = ctx.message.attachments[0] # assuming only one attachment + await attachment.save(self.working_dir + '/' + attachment.filename) + + with open(self.working_dir + '/' + attachment.filename, 'r') as file: + text = file.read() + question = f"Translate the following text to english: {text}" + # Now text contains the content of the downloaded file + translated_text = await self.answer_question(question) + # Save the translated text to a new file + with open(f'{self.working_dir}/translated_text.txt', 'w') as new_file: + new_file.write(translated_text) + + # Send the text file as an attachment + file = discord.File(f'{self.working_dir}/translated_text.txt') + await ctx.send(file=file) + @commands.command( description="Personality", From 4f1322c68499e5a1fe1ebea0901bcdef21d3d3e4 Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 18 Jul 2024 11:50:32 -0700 Subject: [PATCH 09/76] disabled llama as it isn't working properly --- cogs/llama.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cogs/llama.py b/cogs/llama.py index 10e0436..9e67212 100644 --- a/cogs/llama.py +++ b/cogs/llama.py @@ -170,4 +170,6 @@ class Llama(commands.Cog): async def setup(bot): - await bot.add_cog(Llama(bot)) \ No newline at end of file + #await bot.add_cog(Llama(bot)) + #Temporarily disable this as it isn't really working properly + pass \ No newline at end of file From 7c6c012be6471402855448de54820fe2b7c3d504 Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 18 Jul 2024 11:53:27 -0700 Subject: [PATCH 10/76] disabled inky as it is unused --- cogs/inky_phat.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cogs/inky_phat.py b/cogs/inky_phat.py index deed2b2..9878834 100644 --- a/cogs/inky_phat.py +++ b/cogs/inky_phat.py @@ -146,4 +146,6 @@ class InkyScreen(commands.Cog): async def setup(bot): - await bot.add_cog(InkyScreen(bot)) \ No newline at end of file + #await bot.add_cog(InkyScreen(bot)) + #Temporarily disable as this is probably unused for everyone including me + pass \ No newline at end of file From 42ae73030f9f920b1dde9484fcb9583c27342efa Mon Sep 17 00:00:00 2001 From: phixxy Date: Sat, 20 Jul 2024 12:58:51 -0700 Subject: [PATCH 11/76] now use gpt-4o-mini for decreased pricing/better outputs --- cogs/chatgpt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cogs/chatgpt.py b/cogs/chatgpt.py index da7be40..8559a2f 100644 --- a/cogs/chatgpt.py +++ b/cogs/chatgpt.py @@ -52,7 +52,7 @@ class ChatGPT(commands.Cog): self.logger.exception(f"ChatGPT failed to make directories: {e}") def text_cost_calc(self, model, input_tokens, output_tokens): - cost_table = {"gpt-3.5-turbo":{"input_tokens":0.0000005,"output_tokens":0.0000015}, + cost_table = {"gpt-4o-mini":{"input_tokens":0.00000015,"output_tokens":0.0000006}, "gpt-4-turbo-preview":{"input_tokens":0.00001,"output_tokens":0.00003}, "gpt-4-vision-preview":{"input_tokens":0.00001,"output_tokens":0.00003}, "gpt-4o":{"input_tokens":0.000005,"output_tokens":0.000015} @@ -287,7 +287,7 @@ class ChatGPT(commands.Cog): user = self.bot.get_user(reminder_dict["user_id"]) return await user.send(reminder_dict["response"]) - async def answer_question(self, topic, model="gpt-3.5-turbo"): + async def answer_question(self, topic, model="gpt-4o-mini"): data = { "model": model, "messages": [{"role": "user", "content": topic}] @@ -701,7 +701,7 @@ class ChatGPT(commands.Cog): message = ctx.content[0] data = { - "model": "gpt-3.5-turbo", + "model": "gpt-4o-mini", "messages": [{"role": "system", "content": system_msg}, {"role": "user", "content": message}] } From 739cdb710dd425ddcb48cf4e5177b1b83a9c7969 Mon Sep 17 00:00:00 2001 From: phixxy Date: Sat, 20 Jul 2024 13:01:08 -0700 Subject: [PATCH 12/76] use gpt-4.0-mini instead of 3.5 turbo --- cogs/phixxycom.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/phixxycom.py b/cogs/phixxycom.py index ad8788b..84c23d4 100644 --- a/cogs/phixxycom.py +++ b/cogs/phixxycom.py @@ -192,7 +192,7 @@ class PhixxyCom(commands.Cog): except: self.logger.exception("Something went wrong in upload_ftp_ai_images") - async def answer_question(self, topic, model="gpt-3.5-turbo"): + async def answer_question(self, topic, model="gpt-4o-mini"): headers = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {os.getenv("openai.api_key")}', @@ -265,7 +265,7 @@ class PhixxyCom(commands.Cog): topic = await self.answer_question(question) self.logger.info("Writing blogpost") title_prompt = 'generate an absurd essay title about ' + topic - title = await self.answer_question(title_prompt, model="gpt-3.5-turbo") + title = await self.answer_question(title_prompt, model="gpt-4o-mini") prompt = 'Write a satirical essay with a serious tone titled: "' + title + '". Do not label parts of the essay.' content = await self.answer_question(prompt, model="gpt-4o") if title in content[:len(title)]: From 8a3c18b857e875fca48500a27d46da7b9edbc26b Mon Sep 17 00:00:00 2001 From: phixxy Date: Sat, 20 Jul 2024 13:01:47 -0700 Subject: [PATCH 13/76] removed debug statement --- src/webui.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/webui.py b/src/webui.py index a003068..5b4306c 100644 --- a/src/webui.py +++ b/src/webui.py @@ -38,7 +38,6 @@ async def index(): with open('.env', 'w') as file: for key, value in form_dict.items(): file.write(f"{key}='{value}'\n") - print(form_dict) flask_app.bot_process.terminate() flask_app.bot_process = subprocess.Popen([sys.executable, "sparkytron3000.py"]) message = "Variables Updated!" From 3964ec0fc2cef909372b2fc47ad935b532bb6355 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 19:27:14 -0700 Subject: [PATCH 14/76] added a youtube-dl command --- cogs/ytdl.py | 26 ++++++++++++++++++++ data/ytdl/youtubedl.py | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 cogs/ytdl.py create mode 100644 data/ytdl/youtubedl.py diff --git a/cogs/ytdl.py b/cogs/ytdl.py new file mode 100644 index 0000000..6322c2d --- /dev/null +++ b/cogs/ytdl.py @@ -0,0 +1,26 @@ +import os +import subprocess + +from discord.ext import commands +from cogs.base_cog.bot_base_cog import BotBaseCog + +class YoutubeDL(BotBaseCog): + + def __init__(self, bot): + super().__init__(bot) + self.setup(__class__.__name__) + + @commands.command() + async def youtubedl(self, ctx): + try: + url = f"\"{ctx.message.content.split(" ", 1)[1]}\"" + video_or_audio = ctx.message.content.split(" ", 2)[2] + process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) + process.wait() + output = process.returncode + await ctx.send(f"Downloaded {video_or_audio} from {url}, output: {output}") + except: + await ctx.send("Usage: !youtubedl ") + +async def setup(bot): + await bot.add_cog(YoutubeDL(bot)) \ No newline at end of file diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py new file mode 100644 index 0000000..2769e2c --- /dev/null +++ b/data/ytdl/youtubedl.py @@ -0,0 +1,54 @@ +from sys import argv +import os +import time +import subprocess +#usage python3 youtubedl.py + +def download(url, video_or_audio): + if video_or_audio == "video": + process = subprocess.Popen(["yt-dlp", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + print(process.stdout.read()) + process.wait() + return True + elif video_or_audio == "audio": + process = subprocess.Popen(["yt-dlp", "-x", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + print(process.stdout.read()) + process.wait() + return True + else: + print("Invalid argument") + return False + +def zip_all_files(): + #zip all files + current_epoch = time.time() + output_file = f"{current_epoch}.zip" + os.system(f"zip -r {output_file} *") + return output_file + +def upload_to_litterbox(input_file): + ''' If you want to make curl requests to the API, here is an example. Allowed values for "time" are 1h, 12h, 24h, and 72h. + curl -F "reqtype=fileupload" -F "time=1h" -F "fileToUpload=@cutie.png" https://litterbox.catbox.moe/resources/internals/api.php''' + command = f"curl -F 'reqtype=fileupload' -F 'time=1h' -F 'fileToUpload=@{input_file}' https://litterbox.catbox.moe/resources/internals/api.php" + output_url = os.popen(command).read() + #delete all files in current directory except this script + file_types = ["zip", "mp4", "mp3", "webm", "wav", "m4a", "flac", "ogg", "opus", "wma", "aac", "m4p", "m4b", "m4r", "m4v", "mp2", "mp3", "mp4", "mpa", "mpeg", "mpg", "mpv", "mxf", "ogg", "oga", "ogv", "ogx", "spx", "wav", "webm", "wma", "wv", "wvx", "weba", "webm", "webp", "wmv"] + for file in os.listdir(): + if file.split(".")[-1] in file_types: + os.remove(file) + return output_url + +def main(): + url, video_or_audio = argv[1], argv[2] + print(url, video_or_audio) + if download(url, video_or_audio): + zip_file = zip_all_files() + output_url = upload_to_litterbox(zip_file) + print(output_url) + return output_url + else: + print("Invalid argument") + return 1 + +if __name__ == "__main__": + main() From 8b6a59e8208d905327ac47e93cf2ee343c3c5a59 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 19:31:11 -0700 Subject: [PATCH 15/76] fixed quote being appended to url --- cogs/ytdl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 6322c2d..d3985c6 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -13,7 +13,8 @@ class YoutubeDL(BotBaseCog): @commands.command() async def youtubedl(self, ctx): try: - url = f"\"{ctx.message.content.split(" ", 1)[1]}\"" + url = f"{ctx.message.content.split(" ", 1)[1]}" + url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ", 2)[2] process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) process.wait() From d53803370a93c8ea6249f7e82f1914885782883e Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 19:32:09 -0700 Subject: [PATCH 16/76] fixed quote being appended to url --- cogs/ytdl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index d3985c6..a3855a6 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -13,7 +13,7 @@ class YoutubeDL(BotBaseCog): @commands.command() async def youtubedl(self, ctx): try: - url = f"{ctx.message.content.split(" ", 1)[1]}" + url = ctx.message.content.split(" ", 1)[1] url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ", 2)[2] process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) From 3fc4c0475dc90351e4ff722573232496bf6ac2bd Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 19:39:30 -0700 Subject: [PATCH 17/76] fixed error in retreiving litterbox link --- cogs/ytdl.py | 10 +++++++++- data/ytdl/youtubedl.py | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index a3855a6..63ecb71 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -1,7 +1,7 @@ import os import subprocess -from discord.ext import commands +from discord.ext import commands, tasks from cogs.base_cog.bot_base_cog import BotBaseCog class YoutubeDL(BotBaseCog): @@ -22,6 +22,14 @@ class YoutubeDL(BotBaseCog): await ctx.send(f"Downloaded {video_or_audio} from {url}, output: {output}") except: await ctx.send("Usage: !youtubedl ") + + #create a task + @tasks.loop(seconds=10) + async def check_for_downloads(self): + for file in os.listdir("data/ytdl"): + if file.endswith(".txt"): + await self.bot.get_channel(544408659174883328).send(f"{file[:-4]}") + os.remove(f"data/ytdl/{file}") async def setup(bot): await bot.add_cog(YoutubeDL(bot)) \ No newline at end of file diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 2769e2c..409d5f9 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -45,10 +45,11 @@ def main(): zip_file = zip_all_files() output_url = upload_to_litterbox(zip_file) print(output_url) - return output_url + with open(f"data/ytdl/{output_url}.txt", "w") as output_file: + output_file.write(output_url) + output_file.close() else: print("Invalid argument") - return 1 if __name__ == "__main__": main() From a2cfefe02b784bf0cc145bb60a733fb96d860f58 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 19:44:59 -0700 Subject: [PATCH 18/76] remove embed from output message --- cogs/ytdl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 63ecb71..555a47d 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -19,7 +19,7 @@ class YoutubeDL(BotBaseCog): process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) process.wait() output = process.returncode - await ctx.send(f"Downloaded {video_or_audio} from {url}, output: {output}") + await ctx.send(f"Downloading {video_or_audio} from {url}...", embed=None) except: await ctx.send("Usage: !youtubedl ") From 114a24c1cb6ba9e0781de2e0d710b8fdd28008f2 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 19:51:57 -0700 Subject: [PATCH 19/76] debug messages added --- cogs/ytdl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 555a47d..a86eafd 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -18,8 +18,8 @@ class YoutubeDL(BotBaseCog): video_or_audio = ctx.message.content.split(" ", 2)[2] process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) process.wait() - output = process.returncode - await ctx.send(f"Downloading {video_or_audio} from {url}...", embed=None) + await ctx.send(process.stdout) + await ctx.send(f"Downloading {video_or_audio} from {url}...", embeds=None) except: await ctx.send("Usage: !youtubedl ") From 3d2b15510fadfba44e9cbb212d45c15f7757d28b Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 19:54:04 -0700 Subject: [PATCH 20/76] added WIP stuff to gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5637a6d..b52fbef 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ extensions/ .env databases/ channels/ -.gitignore \ No newline at end of file +.gitignore +cogs/dailies.py +cogs/idlegame.py From 80b00b3aea84c1dc774d0ceb65d50a567ade7e43 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 20:08:07 -0700 Subject: [PATCH 21/76] changed working dir and blocking --- cogs/ytdl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index a86eafd..a485ce7 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -16,9 +16,9 @@ class YoutubeDL(BotBaseCog): url = ctx.message.content.split(" ", 1)[1] url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ", 2)[2] - process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) - process.wait() - await ctx.send(process.stdout) + process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio], cwd="data/ytdl/") + #process.wait() + #await ctx.send(process.stdout) await ctx.send(f"Downloading {video_or_audio} from {url}...", embeds=None) except: await ctx.send("Usage: !youtubedl ") From 8fb5f1bee85043a3aadfb4789bb6ec6e5a95f3de Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 20:16:59 -0700 Subject: [PATCH 22/76] fixed cwd? hopefully --- cogs/ytdl.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index a485ce7..39185ca 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -16,9 +16,8 @@ class YoutubeDL(BotBaseCog): url = ctx.message.content.split(" ", 1)[1] url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ", 2)[2] - process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio], cwd="data/ytdl/") - #process.wait() - #await ctx.send(process.stdout) + working_dir = f"{os.getcwd()}/data/ytdl/" + process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio], cwd=working_dir) await ctx.send(f"Downloading {video_or_audio} from {url}...", embeds=None) except: await ctx.send("Usage: !youtubedl ") From 73679351d3dc1a2052ba10c6bd5e056f3cd7c917 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 20:29:58 -0700 Subject: [PATCH 23/76] changed youtubedl.py to just assume cwd is wrong --- cogs/ytdl.py | 5 ++--- data/ytdl/youtubedl.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 39185ca..e438c2d 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -16,9 +16,8 @@ class YoutubeDL(BotBaseCog): url = ctx.message.content.split(" ", 1)[1] url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ", 2)[2] - working_dir = f"{os.getcwd()}/data/ytdl/" - process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio], cwd=working_dir) - await ctx.send(f"Downloading {video_or_audio} from {url}...", embeds=None) + process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) + await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except: await ctx.send("Usage: !youtubedl ") diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 409d5f9..33ed4bf 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -6,12 +6,12 @@ import subprocess def download(url, video_or_audio): if video_or_audio == "video": - process = subprocess.Popen(["yt-dlp", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(process.stdout.read()) process.wait() return True elif video_or_audio == "audio": - process = subprocess.Popen(["yt-dlp", "-x", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "-x", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(process.stdout.read()) process.wait() return True @@ -23,7 +23,7 @@ def zip_all_files(): #zip all files current_epoch = time.time() output_file = f"{current_epoch}.zip" - os.system(f"zip -r {output_file} *") + os.system(f"zip -r {output_file} data/ytdl/*") return output_file def upload_to_litterbox(input_file): From 5b8c433e9516ab2123263b24550a3acab8d73431 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 20:35:52 -0700 Subject: [PATCH 24/76] fixed filename output to not be a url --- cogs/ytdl.py | 4 +++- data/ytdl/youtubedl.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index e438c2d..a48f430 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -26,7 +26,9 @@ class YoutubeDL(BotBaseCog): async def check_for_downloads(self): for file in os.listdir("data/ytdl"): if file.endswith(".txt"): - await self.bot.get_channel(544408659174883328).send(f"{file[:-4]}") + with open(f"data/ytdl/{file}", "r") as f: + url = f.read() + await self.bot.get_channel(544408659174883328).send(f"{url}") os.remove(f"data/ytdl/{file}") async def setup(bot): diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 33ed4bf..dae3e58 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -45,7 +45,7 @@ def main(): zip_file = zip_all_files() output_url = upload_to_litterbox(zip_file) print(output_url) - with open(f"data/ytdl/{output_url}.txt", "w") as output_file: + with open(f"data/ytdl/{time.time()}.txt", "w") as output_file: output_file.write(output_url) output_file.close() else: From 65d6badbf6bd40bb2504cf1c6cdca76e7ee61618 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 20:41:24 -0700 Subject: [PATCH 25/76] added line to start the loop --- cogs/ytdl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index a48f430..d886760 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -9,6 +9,7 @@ class YoutubeDL(BotBaseCog): def __init__(self, bot): super().__init__(bot) self.setup(__class__.__name__) + self.check_for_downloads.start() @commands.command() async def youtubedl(self, ctx): From 3fb59cdff7b34d9020046418878831cffaf0ce36 Mon Sep 17 00:00:00 2001 From: phixxy Date: Wed, 4 Sep 2024 20:59:00 -0700 Subject: [PATCH 26/76] fixed some pathing issues --- data/ytdl/youtubedl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index dae3e58..208ad80 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -6,12 +6,12 @@ import subprocess def download(url, video_or_audio): if video_or_audio == "video": - process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["yt-dlp", "-o", "%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(process.stdout.read()) process.wait() return True elif video_or_audio == "audio": - process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "-x", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["yt-dlp", "-o", "%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "-x", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(process.stdout.read()) process.wait() return True @@ -45,7 +45,7 @@ def main(): zip_file = zip_all_files() output_url = upload_to_litterbox(zip_file) print(output_url) - with open(f"data/ytdl/{time.time()}.txt", "w") as output_file: + with open(f"{time.time()}.txt", "w") as output_file: output_file.write(output_url) output_file.close() else: From 217a93d3a47c68d5d4d11939ef6aef91f7548037 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:01:33 -0700 Subject: [PATCH 27/76] fixed paths --- data/ytdl/youtubedl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 208ad80..cbda8dc 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -23,7 +23,7 @@ def zip_all_files(): #zip all files current_epoch = time.time() output_file = f"{current_epoch}.zip" - os.system(f"zip -r {output_file} data/ytdl/*") + os.system(f"zip -r data/ytdl/{output_file} data/ytdl/*") return output_file def upload_to_litterbox(input_file): From 5d8edfab0a6ccf7833f0886c430b948a7d7a0e28 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:04:48 -0700 Subject: [PATCH 28/76] fixed paths in litterbox --- data/ytdl/youtubedl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index cbda8dc..ffeb8e8 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -29,13 +29,13 @@ def zip_all_files(): def upload_to_litterbox(input_file): ''' If you want to make curl requests to the API, here is an example. Allowed values for "time" are 1h, 12h, 24h, and 72h. curl -F "reqtype=fileupload" -F "time=1h" -F "fileToUpload=@cutie.png" https://litterbox.catbox.moe/resources/internals/api.php''' - command = f"curl -F 'reqtype=fileupload' -F 'time=1h' -F 'fileToUpload=@{input_file}' https://litterbox.catbox.moe/resources/internals/api.php" + command = f"curl -F 'reqtype=fileupload' -F 'time=1h' -F 'fileToUpload=@data/ytdl/{input_file}' https://litterbox.catbox.moe/resources/internals/api.php" output_url = os.popen(command).read() #delete all files in current directory except this script file_types = ["zip", "mp4", "mp3", "webm", "wav", "m4a", "flac", "ogg", "opus", "wma", "aac", "m4p", "m4b", "m4r", "m4v", "mp2", "mp3", "mp4", "mpa", "mpeg", "mpg", "mpv", "mxf", "ogg", "oga", "ogv", "ogx", "spx", "wav", "webm", "wma", "wv", "wvx", "weba", "webm", "webp", "wmv"] - for file in os.listdir(): + for file in os.listdir("data/ytdl/"): if file.split(".")[-1] in file_types: - os.remove(file) + os.remove(f"data/ytdl/{file}") return output_url def main(): From b45db6c54b5a2484ad77cb4a01e41e06ca484099 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:07:06 -0700 Subject: [PATCH 29/76] fixed url parsing --- cogs/ytdl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index d886760..ffe5174 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -14,9 +14,9 @@ class YoutubeDL(BotBaseCog): @commands.command() async def youtubedl(self, ctx): try: - url = ctx.message.content.split(" ", 1)[1] + url = ctx.message.content.split(" ")[1] url = '"' + url + '"' - video_or_audio = ctx.message.content.split(" ", 2)[2] + video_or_audio = ctx.message.content.split(" ")[2] process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except: From d6fd8f7b7b3e1ba21ae877c630cea7ece5bb7107 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:12:30 -0700 Subject: [PATCH 30/76] updated save path for text file --- data/ytdl/youtubedl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index ffeb8e8..2edd8dc 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -45,7 +45,7 @@ def main(): zip_file = zip_all_files() output_url = upload_to_litterbox(zip_file) print(output_url) - with open(f"{time.time()}.txt", "w") as output_file: + with open(f"data/ytdl/{time.time()}.txt", "w") as output_file: output_file.write(output_url) output_file.close() else: From dfc43de1a09529a4fd2c6e926025405d96ae51b7 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:18:46 -0700 Subject: [PATCH 31/76] log some info about ytdl --- cogs/ytdl.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index ffe5174..99057a7 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -18,6 +18,10 @@ class YoutubeDL(BotBaseCog): url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ")[2] process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) + process.wait() + print(process.stdout.read()) + print(process.stderr.read()) + print(process.returncode) await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except: await ctx.send("Usage: !youtubedl ") From 7237cb8da98fe808c77817e36b0fea229e4309a4 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:19:03 -0700 Subject: [PATCH 32/76] log info about ytdl --- cogs/ytdl.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 99057a7..83fe6e8 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -1,5 +1,6 @@ import os import subprocess +import logging from discord.ext import commands, tasks from cogs.base_cog.bot_base_cog import BotBaseCog @@ -19,9 +20,9 @@ class YoutubeDL(BotBaseCog): video_or_audio = ctx.message.content.split(" ")[2] process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) process.wait() - print(process.stdout.read()) - print(process.stderr.read()) - print(process.returncode) + logging.info(process.stdout.read()) + logging.info(process.stderr.read()) + logging.info(process.returncode) await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except: await ctx.send("Usage: !youtubedl ") From fe3993bda89dccdeebcf75981e8ccd3045d05175 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:22:22 -0700 Subject: [PATCH 33/76] change saving path and error logging --- cogs/ytdl.py | 6 +++--- data/ytdl/youtubedl.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 83fe6e8..00aaccc 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -20,9 +20,9 @@ class YoutubeDL(BotBaseCog): video_or_audio = ctx.message.content.split(" ")[2] process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) process.wait() - logging.info(process.stdout.read()) - logging.info(process.stderr.read()) - logging.info(process.returncode) + logging.error(process.stdout.read()) + logging.error(process.stderr.read()) + logging.error(process.returncode) await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except: await ctx.send("Usage: !youtubedl ") diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 2edd8dc..de2071b 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -6,12 +6,12 @@ import subprocess def download(url, video_or_audio): if video_or_audio == "video": - process = subprocess.Popen(["yt-dlp", "-o", "%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(process.stdout.read()) process.wait() return True elif video_or_audio == "audio": - process = subprocess.Popen(["yt-dlp", "-o", "%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "-x", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "-x", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(process.stdout.read()) process.wait() return True From 9345d005ebc8414ccb1d9a9ebc4f74c89587ed63 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:23:58 -0700 Subject: [PATCH 34/76] error logging --- cogs/ytdl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 00aaccc..cc7f1c2 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -24,7 +24,8 @@ class YoutubeDL(BotBaseCog): logging.error(process.stderr.read()) logging.error(process.returncode) await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) - except: + except Exception as e: + await ctx.send(f"Error: {e}") await ctx.send("Usage: !youtubedl ") #create a task From 51c6e6627e1aee855ee91ef9c4cc4598ef1f1bc7 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:24:40 -0700 Subject: [PATCH 35/76] fixed error with stderr/stdout --- cogs/ytdl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index cc7f1c2..e4c6d4f 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -20,8 +20,8 @@ class YoutubeDL(BotBaseCog): video_or_audio = ctx.message.content.split(" ")[2] process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) process.wait() - logging.error(process.stdout.read()) - logging.error(process.stderr.read()) + logging.error(process.stdout) + logging.error(process.stderr) logging.error(process.returncode) await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except Exception as e: From b91df5435d495700dfbac169a6afda1a3003b693 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:26:09 -0700 Subject: [PATCH 36/76] stop removing files so i can see whats happening --- cogs/ytdl.py | 2 +- data/ytdl/youtubedl.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index e4c6d4f..264c0e6 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -36,7 +36,7 @@ class YoutubeDL(BotBaseCog): with open(f"data/ytdl/{file}", "r") as f: url = f.read() await self.bot.get_channel(544408659174883328).send(f"{url}") - os.remove(f"data/ytdl/{file}") + #os.remove(f"data/ytdl/{file}") async def setup(bot): await bot.add_cog(YoutubeDL(bot)) \ No newline at end of file diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index de2071b..c7d572c 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -35,7 +35,8 @@ def upload_to_litterbox(input_file): file_types = ["zip", "mp4", "mp3", "webm", "wav", "m4a", "flac", "ogg", "opus", "wma", "aac", "m4p", "m4b", "m4r", "m4v", "mp2", "mp3", "mp4", "mpa", "mpeg", "mpg", "mpv", "mxf", "ogg", "oga", "ogv", "ogx", "spx", "wav", "webm", "wma", "wv", "wvx", "weba", "webm", "webp", "wmv"] for file in os.listdir("data/ytdl/"): if file.split(".")[-1] in file_types: - os.remove(f"data/ytdl/{file}") + #os.remove(f"data/ytdl/{file}") + pass return output_url def main(): From 9fb5b023d0ee50ee6066d863102211dfd6a3c564 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:30:17 -0700 Subject: [PATCH 37/76] log errors properly --- cogs/ytdl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 264c0e6..958a2b8 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -20,9 +20,9 @@ class YoutubeDL(BotBaseCog): video_or_audio = ctx.message.content.split(" ")[2] process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) process.wait() - logging.error(process.stdout) - logging.error(process.stderr) - logging.error(process.returncode) + self.logger.exception(process.stdout) + self.logger.exception(process.stderr) + self.logger.exception(process.returncode) await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except Exception as e: await ctx.send(f"Error: {e}") From 010c57247ba829a79e664f37ee8d5b66ea5c18a9 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:30:56 -0700 Subject: [PATCH 38/76] stop uploading to litterbox while debugging --- data/ytdl/youtubedl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index c7d572c..4daf01d 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -44,7 +44,8 @@ def main(): print(url, video_or_audio) if download(url, video_or_audio): zip_file = zip_all_files() - output_url = upload_to_litterbox(zip_file) + #output_url = upload_to_litterbox(zip_file) + output_url = "test_url" print(output_url) with open(f"data/ytdl/{time.time()}.txt", "w") as output_file: output_file.write(output_url) From 2151a5d93ad32cd57d68f23b4a3332890dbd21b2 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:36:57 -0700 Subject: [PATCH 39/76] debug msgs --- data/ytdl/youtubedl.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 4daf01d..0d65afc 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -49,6 +49,8 @@ def main(): print(output_url) with open(f"data/ytdl/{time.time()}.txt", "w") as output_file: output_file.write(output_url) + output_file.write("\n") + output_file.write(os.getcwd()) output_file.close() else: print("Invalid argument") From e5223e829621946dea377e3e54960ede2e203cef Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:39:59 -0700 Subject: [PATCH 40/76] change output dir --- data/ytdl/youtubedl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 0d65afc..5928c9e 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -11,7 +11,7 @@ def download(url, video_or_audio): process.wait() return True elif video_or_audio == "audio": - process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "-x", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["yt-dlp", "-x", "--yes-playlist", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(process.stdout.read()) process.wait() return True From 2141abae5e0dca66e851d9b575082ba54205e952 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:41:53 -0700 Subject: [PATCH 41/76] removed probable syntax error --- data/ytdl/youtubedl.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 5928c9e..131b57e 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -7,12 +7,10 @@ import subprocess def download(url, video_or_audio): if video_or_audio == "video": process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - print(process.stdout.read()) process.wait() return True elif video_or_audio == "audio": process = subprocess.Popen(["yt-dlp", "-x", "--yes-playlist", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - print(process.stdout.read()) process.wait() return True else: From ee267275d6faf4959172c63b6b59f90e9394f1be Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:56:58 -0700 Subject: [PATCH 42/76] removed directory assumptions, trying to use chdir --- cogs/ytdl.py | 4 +++- data/ytdl/youtubedl.py | 14 ++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 958a2b8..6894d1e 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -18,7 +18,9 @@ class YoutubeDL(BotBaseCog): url = ctx.message.content.split(" ")[1] url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ")[2] - process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) + os.chdir("data/ytdl") + process = subprocess.Popen(["python3", "youtubedl.py", url, video_or_audio]) + os.chdir("../../") process.wait() self.logger.exception(process.stdout) self.logger.exception(process.stderr) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 131b57e..6caf167 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -6,7 +6,7 @@ import subprocess def download(url, video_or_audio): if video_or_audio == "video": - process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["yt-dlp", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) process.wait() return True elif video_or_audio == "audio": @@ -21,19 +21,19 @@ def zip_all_files(): #zip all files current_epoch = time.time() output_file = f"{current_epoch}.zip" - os.system(f"zip -r data/ytdl/{output_file} data/ytdl/*") + os.system(f"zip -r {output_file} *") return output_file def upload_to_litterbox(input_file): ''' If you want to make curl requests to the API, here is an example. Allowed values for "time" are 1h, 12h, 24h, and 72h. curl -F "reqtype=fileupload" -F "time=1h" -F "fileToUpload=@cutie.png" https://litterbox.catbox.moe/resources/internals/api.php''' - command = f"curl -F 'reqtype=fileupload' -F 'time=1h' -F 'fileToUpload=@data/ytdl/{input_file}' https://litterbox.catbox.moe/resources/internals/api.php" + command = f"curl -F 'reqtype=fileupload' -F 'time=1h' -F 'fileToUpload=@{input_file}' https://litterbox.catbox.moe/resources/internals/api.php" output_url = os.popen(command).read() #delete all files in current directory except this script file_types = ["zip", "mp4", "mp3", "webm", "wav", "m4a", "flac", "ogg", "opus", "wma", "aac", "m4p", "m4b", "m4r", "m4v", "mp2", "mp3", "mp4", "mpa", "mpeg", "mpg", "mpv", "mxf", "ogg", "oga", "ogv", "ogx", "spx", "wav", "webm", "wma", "wv", "wvx", "weba", "webm", "webp", "wmv"] - for file in os.listdir("data/ytdl/"): + for file in os.listdir(): if file.split(".")[-1] in file_types: - #os.remove(f"data/ytdl/{file}") + #os.remove(f"{file}") pass return output_url @@ -45,10 +45,8 @@ def main(): #output_url = upload_to_litterbox(zip_file) output_url = "test_url" print(output_url) - with open(f"data/ytdl/{time.time()}.txt", "w") as output_file: + with open(f"{time.time()}.txt", "w") as output_file: output_file.write(output_url) - output_file.write("\n") - output_file.write(os.getcwd()) output_file.close() else: print("Invalid argument") From 8b7b1aaadad80fd3015863725d6d5a1deb081ab8 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 23:04:05 -0700 Subject: [PATCH 43/76] cwd stuff --- cogs/ytdl.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 6894d1e..557ca8f 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -18,13 +18,8 @@ class YoutubeDL(BotBaseCog): url = ctx.message.content.split(" ")[1] url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ")[2] - os.chdir("data/ytdl") - process = subprocess.Popen(["python3", "youtubedl.py", url, video_or_audio]) - os.chdir("../../") + process = subprocess.Popen(["python3", "youtubedl.py", url, video_or_audio], cwd="data/ytdl") process.wait() - self.logger.exception(process.stdout) - self.logger.exception(process.stderr) - self.logger.exception(process.returncode) await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except Exception as e: await ctx.send(f"Error: {e}") From c1d815e7d5158013269297e60316e069b8519e05 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 23:06:58 -0700 Subject: [PATCH 44/76] print stdout and stderr --- cogs/ytdl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 557ca8f..c3fc2fe 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -18,8 +18,9 @@ class YoutubeDL(BotBaseCog): url = ctx.message.content.split(" ")[1] url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ")[2] - process = subprocess.Popen(["python3", "youtubedl.py", url, video_or_audio], cwd="data/ytdl") + process = subprocess.Popen(["python3", "youtubedl.py", url, video_or_audio], cwd="data/ytdl", stdout=subprocess.PIPE, stderr=subprocess.PIPE) process.wait() + await ctx.send(f"std out: {process.stdout.read()}, std err: {process.stderr.read()}") await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except Exception as e: await ctx.send(f"Error: {e}") From d9968bd5005cd673f8646bff0c3181e8540eea21 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 23:11:31 -0700 Subject: [PATCH 45/76] try chatgpts solution --- cogs/ytdl.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index c3fc2fe..41c4286 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -15,13 +15,31 @@ class YoutubeDL(BotBaseCog): @commands.command() async def youtubedl(self, ctx): try: - url = ctx.message.content.split(" ")[1] - url = '"' + url + '"' - video_or_audio = ctx.message.content.split(" ")[2] - process = subprocess.Popen(["python3", "youtubedl.py", url, video_or_audio], cwd="data/ytdl", stdout=subprocess.PIPE, stderr=subprocess.PIPE) - process.wait() - await ctx.send(f"std out: {process.stdout.read()}, std err: {process.stderr.read()}") + # Expecting the command format to be !youtubedl + parts = ctx.message.content.split(" ") + if len(parts) < 3: + await ctx.send("Usage: !youtubedl ") + return + + url = parts[1] + video_or_audio = parts[2] + + # Run the subprocess + process = subprocess.Popen( + ["python3", "youtubedl.py", url, video_or_audio], + cwd="data/ytdl", + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + + # Wait for the process to complete and read the output + stdout, stderr = process.communicate() + + # Send the output back to the user + await ctx.send(f"std out: {stdout.decode('utf-8')}") if stdout else await ctx.send("No stdout output") + await ctx.send(f"std err: {stderr.decode('utf-8')}") if stderr else await ctx.send("No stderr output") await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) + except Exception as e: await ctx.send(f"Error: {e}") await ctx.send("Usage: !youtubedl ") From 1399ebca7b34e422edbac7c65c41a3b0d4d4a692 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 23:15:02 -0700 Subject: [PATCH 46/76] re-enable upload to litterbox --- cogs/ytdl.py | 8 ++++---- data/ytdl/youtubedl.py | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 41c4286..c068872 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -36,12 +36,12 @@ class YoutubeDL(BotBaseCog): stdout, stderr = process.communicate() # Send the output back to the user - await ctx.send(f"std out: {stdout.decode('utf-8')}") if stdout else await ctx.send("No stdout output") - await ctx.send(f"std err: {stderr.decode('utf-8')}") if stderr else await ctx.send("No stderr output") + #await ctx.send(f"std out: {stdout.decode('utf-8')}") if stdout else await ctx.send("No stdout output") + #await ctx.send(f"std err: {stderr.decode('utf-8')}") if stderr else await ctx.send("No stderr output") await ctx.send(f"Downloading {video_or_audio} from {url}...", suppress_embeds=True) except Exception as e: - await ctx.send(f"Error: {e}") + #await ctx.send(f"Error: {e}") await ctx.send("Usage: !youtubedl ") #create a task @@ -52,7 +52,7 @@ class YoutubeDL(BotBaseCog): with open(f"data/ytdl/{file}", "r") as f: url = f.read() await self.bot.get_channel(544408659174883328).send(f"{url}") - #os.remove(f"data/ytdl/{file}") + os.remove(f"data/ytdl/{file}") async def setup(bot): await bot.add_cog(YoutubeDL(bot)) \ No newline at end of file diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 6caf167..6f594aa 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -42,8 +42,7 @@ def main(): print(url, video_or_audio) if download(url, video_or_audio): zip_file = zip_all_files() - #output_url = upload_to_litterbox(zip_file) - output_url = "test_url" + output_url = upload_to_litterbox(zip_file) print(output_url) with open(f"{time.time()}.txt", "w") as output_file: output_file.write(output_url) From 71bb156d8b48bf5e5fab41eeb515be507adfd934 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 23:17:28 -0700 Subject: [PATCH 47/76] delete files after uploading --- data/ytdl/youtubedl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 6f594aa..1814d03 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -33,7 +33,7 @@ def upload_to_litterbox(input_file): file_types = ["zip", "mp4", "mp3", "webm", "wav", "m4a", "flac", "ogg", "opus", "wma", "aac", "m4p", "m4b", "m4r", "m4v", "mp2", "mp3", "mp4", "mpa", "mpeg", "mpg", "mpv", "mxf", "ogg", "oga", "ogv", "ogx", "spx", "wav", "webm", "wma", "wv", "wvx", "weba", "webm", "webp", "wmv"] for file in os.listdir(): if file.split(".")[-1] in file_types: - #os.remove(f"{file}") + os.remove(f"{file}") pass return output_url From 8756947298e1e0f4240199be5c087c61111da217 Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 5 Sep 2024 18:43:40 -0700 Subject: [PATCH 48/76] make function async --- cogs/ytdl.py | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index c068872..09d2b06 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -1,6 +1,6 @@ import os import subprocess -import logging +import asyncio from discord.ext import commands, tasks from cogs.base_cog.bot_base_cog import BotBaseCog @@ -12,7 +12,7 @@ class YoutubeDL(BotBaseCog): self.setup(__class__.__name__) self.check_for_downloads.start() - @commands.command() + ''' @commands.command() async def youtubedl(self, ctx): try: # Expecting the command format to be !youtubedl @@ -42,8 +42,43 @@ class YoutubeDL(BotBaseCog): except Exception as e: #await ctx.send(f"Error: {e}") - await ctx.send("Usage: !youtubedl ") + await ctx.send("Usage: !youtubedl ")''' + + @commands.command() + async def youtubedl(self, ctx): + try: + # Expecting the command format to be !youtubedl + parts = ctx.message.content.split(" ") + if len(parts) < 3: + await ctx.send("Usage: !youtubedl ") + return + + url = parts[1] + video_or_audio = parts[2] + # Create a subprocess + process = await asyncio.create_subprocess_exec( + "python3", "youtubedl.py", url, video_or_audio, + cwd="data/ytdl", + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE + ) + + # Write a message that the download has started + await ctx.send(f"Downloading {video_or_audio} from {url}...") + + # Read stdout and stderr (non-blocking) + stdout, stderr = await process.communicate() + + # Send the output back to the user + if stdout: + await ctx.send(f"std out: {stdout.decode('utf-8')}") + if stderr: + await ctx.send(f"std err: {stderr.decode('utf-8')}") + + except Exception as e: + await ctx.send(f"Error: {e}") + #create a task @tasks.loop(seconds=10) async def check_for_downloads(self): From c0a5dda5d26e6e9f56b27ab5c9a1c81f4a388656 Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:23:21 -0800 Subject: [PATCH 49/76] start replacement of highscores.py --- cogs/message_xp.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 cogs/message_xp.py diff --git a/cogs/message_xp.py b/cogs/message_xp.py new file mode 100644 index 0000000..7405366 --- /dev/null +++ b/cogs/message_xp.py @@ -0,0 +1,57 @@ +from discord.ext import commands +import json +import os +from cogs.base_cog.bot_base_cog import BotBaseCog + +class MessageXP(BotBaseCog): + + def __init__(self, bot): + super().__init__(bot) + self.setup(__class__.__name__) + + @commands.command() + async def stats(self, ctx): + author_id = ctx.author.id + if not os.path.exists(self.data_dir + "xp.json"): + create_xp_file(self) + try: + with open(self.data_dir + "xp.json", "r") as xp_file: + xp_data = json.load(xp_file) + xp_file.close() + if author_id in xp_data: + await ctx.send(f"You have {xp_data[author_id]} XP") + else: + await ctx.send("You have 0 XP") + except: + await ctx.send("Error getting XP") + + + @commands.Cog.listener() + async def on_message(self, message: discord.Message): + author_id = message.author.id + if author_id == self.bot_id: + return + else: + #check if file exists + if not os.path.exists(self.data_dir + "xp.json"): + create_xp_file(self) + with open(self.data_dir + "xp.json", "r") as xp_file: + xp_data = json.load(xp_file) + xp_file.close() + if author_id in xp_data: + xp_data[author_id] += 1 + else: + xp_data[author_id] = 1 + with open(self.data_dir + "xp.json", "w") as xp_file: + json.dump(xp_data, xp_file) + xp_file.close() + +def create_xp_file(self): + with open(self.data_dir + "xp.json", "w") as xp_file: + xp_data = {} + json.dump(xp_data, xp_file) + xp_file.close() + + +async def setup(bot): + await bot.add_cog(MessageXP(bot)) \ No newline at end of file From 5e58f4596735a03515a4bdcbd2c29cfaf9d4a33c Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:25:13 -0800 Subject: [PATCH 50/76] added discord import --- cogs/message_xp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 7405366..5e5bce5 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -1,4 +1,5 @@ from discord.ext import commands +import discord import json import os from cogs.base_cog.bot_base_cog import BotBaseCog From ddca750093b795b14194ce95519ff7066fcd894e Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:33:11 -0800 Subject: [PATCH 51/76] removed unneeded xp_file.close() calls --- cogs/message_xp.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 5e5bce5..32f99a7 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -34,24 +34,24 @@ class MessageXP(BotBaseCog): return else: #check if file exists - if not os.path.exists(self.data_dir + "xp.json"): + if not os.path.exists(os.path.join(self.data_dir, "xp.json")): create_xp_file(self) - with open(self.data_dir + "xp.json", "r") as xp_file: + + with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: xp_data = json.load(xp_file) - xp_file.close() + if author_id in xp_data: xp_data[author_id] += 1 else: xp_data[author_id] = 1 - with open(self.data_dir + "xp.json", "w") as xp_file: - json.dump(xp_data, xp_file) - xp_file.close() + + with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: + json.dump(xp_data, xp_file) def create_xp_file(self): with open(self.data_dir + "xp.json", "w") as xp_file: xp_data = {} json.dump(xp_data, xp_file) - xp_file.close() async def setup(bot): From 487d91ba2e9688774f6fea92d14f7317e291735d Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:36:14 -0800 Subject: [PATCH 52/76] added error logging --- cogs/message_xp.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 32f99a7..f94a4e5 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -29,24 +29,27 @@ class MessageXP(BotBaseCog): @commands.Cog.listener() async def on_message(self, message: discord.Message): - author_id = message.author.id - if author_id == self.bot_id: - return - else: - #check if file exists - if not os.path.exists(os.path.join(self.data_dir, "xp.json")): - create_xp_file(self) - - with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: - xp_data = json.load(xp_file) - - if author_id in xp_data: - xp_data[author_id] += 1 + try: + author_id = message.author.id + if author_id == self.bot_id: + return else: - xp_data[author_id] = 1 + #check if file exists + if not os.path.exists(os.path.join(self.data_dir, "xp.json")): + create_xp_file(self) - with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: - json.dump(xp_data, xp_file) + with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: + xp_data = json.load(xp_file) + + if author_id in xp_data: + xp_data[author_id] += 1 + else: + xp_data[author_id] = 1 + + with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: + json.dump(xp_data, xp_file) + except Exception as e: + self.logger.error(f"Error adding XP: {e}") def create_xp_file(self): with open(self.data_dir + "xp.json", "w") as xp_file: From 9228c9a66187b617eb5757cf188575deb373899f Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:38:17 -0800 Subject: [PATCH 53/76] properly check if message isn't sent from bots --- cogs/message_xp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index f94a4e5..45c9d58 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -31,7 +31,7 @@ class MessageXP(BotBaseCog): async def on_message(self, message: discord.Message): try: author_id = message.author.id - if author_id == self.bot_id: + if message.author.bot: return else: #check if file exists From ef9c64ec9da98b05d395a437c2e4ceeca7aa82c4 Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:41:07 -0800 Subject: [PATCH 54/76] safely join path with os.path.join --- cogs/message_xp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 45c9d58..34dbbf5 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -52,7 +52,7 @@ class MessageXP(BotBaseCog): self.logger.error(f"Error adding XP: {e}") def create_xp_file(self): - with open(self.data_dir + "xp.json", "w") as xp_file: + with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: xp_data = {} json.dump(xp_data, xp_file) From ff5ac25392df2a46cc5e95b1d22a9eb64be9e49f Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:43:58 -0800 Subject: [PATCH 55/76] check that directory exists --- cogs/message_xp.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 34dbbf5..7291fb8 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -52,9 +52,13 @@ class MessageXP(BotBaseCog): self.logger.error(f"Error adding XP: {e}") def create_xp_file(self): - with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: - xp_data = {} - json.dump(xp_data, xp_file) + os.makedirs(self.data_dir, exist_ok=True) # Ensure the directory exists + xp_data = {} # Populate this with the required data + try: + with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: + json.dump(xp_data, xp_file) + except: + self.logger.error(f"Error creating XP file: {e}") async def setup(bot): From 658cff47c9e58578a198abcbdc980de14ccbbb0c Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:44:18 -0800 Subject: [PATCH 56/76] check that directory exists --- cogs/message_xp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 7291fb8..74b5fa8 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -53,7 +53,7 @@ class MessageXP(BotBaseCog): def create_xp_file(self): os.makedirs(self.data_dir, exist_ok=True) # Ensure the directory exists - xp_data = {} # Populate this with the required data + xp_data = {} try: with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: json.dump(xp_data, xp_file) From f9dfc29a8e2a36d8aa564f1b607686189d7834e6 Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:47:32 -0800 Subject: [PATCH 57/76] added debug function and fixed error logging --- cogs/message_xp.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 74b5fa8..892f40e 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -25,6 +25,12 @@ class MessageXP(BotBaseCog): await ctx.send("You have 0 XP") except: await ctx.send("Error getting XP") + + @commands.command() + async def show_json(self, ctx): + with open(self.data_dir + "xp.json", "r") as xp_file: + xp_data = json.load(xp_file) + await ctx.send(xp_data) @commands.Cog.listener() @@ -57,7 +63,7 @@ def create_xp_file(self): try: with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: json.dump(xp_data, xp_file) - except: + except Exception as e: self.logger.error(f"Error creating XP file: {e}") From 771592ccdbe7a1728500ab66274dbbc54e437652 Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:56:27 -0800 Subject: [PATCH 58/76] spam my server --- cogs/message_xp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 892f40e..6897d49 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -46,7 +46,7 @@ class MessageXP(BotBaseCog): with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: xp_data = json.load(xp_file) - + await message.reply(f"Your author id is: {author_id}") if author_id in xp_data: xp_data[author_id] += 1 else: From 38121d22196efdeed0d94331bbf9657fce3a3aaa Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 17:58:39 -0800 Subject: [PATCH 59/76] use proper path joining everywhere --- cogs/message_xp.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 6897d49..a36b00b 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -13,12 +13,11 @@ class MessageXP(BotBaseCog): @commands.command() async def stats(self, ctx): author_id = ctx.author.id - if not os.path.exists(self.data_dir + "xp.json"): + if not os.path.exists(os.path.join(self.data_dir, "xp.json")): create_xp_file(self) try: - with open(self.data_dir + "xp.json", "r") as xp_file: + with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: xp_data = json.load(xp_file) - xp_file.close() if author_id in xp_data: await ctx.send(f"You have {xp_data[author_id]} XP") else: @@ -28,7 +27,7 @@ class MessageXP(BotBaseCog): @commands.command() async def show_json(self, ctx): - with open(self.data_dir + "xp.json", "r") as xp_file: + with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: xp_data = json.load(xp_file) await ctx.send(xp_data) @@ -46,7 +45,6 @@ class MessageXP(BotBaseCog): with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: xp_data = json.load(xp_file) - await message.reply(f"Your author id is: {author_id}") if author_id in xp_data: xp_data[author_id] += 1 else: From 8325118a2d3e77019862666f130c8270e5455db2 Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 5 Nov 2024 18:39:30 -0800 Subject: [PATCH 60/76] Declare xp --- cogs/message_xp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index a36b00b..dc23834 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -13,6 +13,7 @@ class MessageXP(BotBaseCog): @commands.command() async def stats(self, ctx): author_id = ctx.author.id + xp_data = {} if not os.path.exists(os.path.join(self.data_dir, "xp.json")): create_xp_file(self) try: @@ -39,6 +40,7 @@ class MessageXP(BotBaseCog): if message.author.bot: return else: + xp_data = {} #check if file exists if not os.path.exists(os.path.join(self.data_dir, "xp.json")): create_xp_file(self) From 907c23176c8f314b19cce9777ff3d91f4ef8b832 Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 7 Nov 2024 19:09:28 -0800 Subject: [PATCH 61/76] str author id to see if that fixes json issues --- cogs/message_xp.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index dc23834..37af482 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -12,13 +12,9 @@ class MessageXP(BotBaseCog): @commands.command() async def stats(self, ctx): - author_id = ctx.author.id - xp_data = {} - if not os.path.exists(os.path.join(self.data_dir, "xp.json")): - create_xp_file(self) + author_id = str(ctx.author.id) try: - with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: - xp_data = json.load(xp_file) + xp_data = read_xp_file(self) if author_id in xp_data: await ctx.send(f"You have {xp_data[author_id]} XP") else: @@ -36,17 +32,11 @@ class MessageXP(BotBaseCog): @commands.Cog.listener() async def on_message(self, message: discord.Message): try: - author_id = message.author.id + author_id = str(message.author.id) if message.author.bot: return else: - xp_data = {} - #check if file exists - if not os.path.exists(os.path.join(self.data_dir, "xp.json")): - create_xp_file(self) - - with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: - xp_data = json.load(xp_file) + xp_data = read_xp_file(self) if author_id in xp_data: xp_data[author_id] += 1 else: @@ -57,14 +47,14 @@ class MessageXP(BotBaseCog): except Exception as e: self.logger.error(f"Error adding XP: {e}") -def create_xp_file(self): - os.makedirs(self.data_dir, exist_ok=True) # Ensure the directory exists - xp_data = {} +def read_xp_file(self): try: - with open(os.path.join(self.data_dir, "xp.json"), "w") as xp_file: - json.dump(xp_data, xp_file) + with open(os.path.join(self.data_dir, "xp.json"), "r") as xp_file: + xp_data = json.load(xp_file) + return xp_data except Exception as e: - self.logger.error(f"Error creating XP file: {e}") + self.logger.error(f"No XP file found. Returning empty json object: {e}") + return {} async def setup(bot): From 697a7df551b5cff736e5d1a2b232281e034a4371 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Fri, 29 Nov 2024 21:51:28 -0800 Subject: [PATCH 62/76] Added level to message_xp.py !stats --- cogs/message_xp.py | 110 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/cogs/message_xp.py b/cogs/message_xp.py index 37af482..a72c98b 100644 --- a/cogs/message_xp.py +++ b/cogs/message_xp.py @@ -16,7 +16,8 @@ class MessageXP(BotBaseCog): try: xp_data = read_xp_file(self) if author_id in xp_data: - await ctx.send(f"You have {xp_data[author_id]} XP") + level = get_level_from_xp(xp_data[author_id]) + await ctx.send(f"You are level {level} with {xp_data[author_id]} XP") else: await ctx.send("You have 0 XP") except: @@ -55,6 +56,113 @@ def read_xp_file(self): except Exception as e: self.logger.error(f"No XP file found. Returning empty json object: {e}") return {} + +def get_level_from_xp(xp): + xp_dict = { + 1: 0, + 2: 83, + 3: 174, + 4: 276, + 5: 388, + 6: 512, + 7: 650, + 8: 801, + 9: 801, + 10: 1_154, + 11: 1_358, + 12: 1_584, + 13: 1_833, + 14: 2_107, + 15: 2_411, + 16: 2_746, + 17: 3_115, + 18: 3_523, + 19: 3_973, + 20: 4_470, + 21: 5_018, + 22: 5_624, + 23: 6_291, + 24: 7_028, + 25: 7_842, + 26: 8_740, + 27: 9_730, + 28: 10_824, + 29: 12_031, + 30: 13_363, + 31: 14_833, + 32: 16_456, + 33: 18_247, + 34: 20_224, + 35: 22_406, + 36: 24_815, + 37: 27_473, + 38: 30_408, + 39: 33_648, + 40: 37_224, + 41: 41_171, + 42: 45_529, + 43: 50_339, + 44: 55_649, + 45: 61_512, + 46: 67_983, + 47: 75_127, + 48: 83_014, + 49: 91_721, + 50: 101_333, + 51: 111_945, + 52: 123_660, + 53: 136_594, + 54: 150_872, + 55: 166_636, + 56: 184_040, + 57: 203_254, + 58: 224_466, + 59: 247_886, + 60: 273_742, + 61: 302_288, + 62: 333_804, + 63: 368_599, + 64: 407_015, + 65: 449_428, + 66: 496_254, + 67: 547_953, + 68: 605_032, + 69: 668_051, + 70: 737_627, + 71: 814_445, + 72: 899_257, + 73: 992_895, + 74: 1_096_278, + 75: 1_210_421, + 76: 1_336_443, + 77: 1_475_581, + 78: 1_629_200, + 79: 1_798_808, + 80: 1_986_068, + 81: 2_192_818, + 82: 2_421_087, + 83: 2_673_114, + 84: 2_951_373, + 85: 3_258_594, + 86: 3_597_792, + 87: 3_972_294, + 88: 4_385_776, + 89: 4_842_295, + 90: 5_346_332, + 91: 5_902_831, + 92: 6_517_253, + 93: 7_195_629, + 94: 7_944_614, + 95: 8_771_558, + 96: 9_684_577, + 97: 10_692_629, + 98: 11_805_606, + 99: 13_034_431 + } + for level, xp_threshold in xp_dict.items(): + if xp < xp_threshold: + return level - 1 + return 99 async def setup(bot): From 1ae4b47391c2b809a967db88aa9c6cf86b20da5b Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 18:17:01 -0800 Subject: [PATCH 63/76] added rss feed to spam a chat with stupid crap --- cogs/rss_feeds.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 cogs/rss_feeds.py diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py new file mode 100644 index 0000000..b59d55e --- /dev/null +++ b/cogs/rss_feeds.py @@ -0,0 +1,29 @@ +from discord.ext import commands, tasks +from cogs.base_cog.bot_base_cog import BotBaseCog +import feedparser + +class RSSCog(BotBaseCog): + + def __init__(self, bot): + super().__init__(bot) + self.setup(__class__.__name__) + self.rss_url = 'https://secure.runescape.com/m=adventurers-log/rssfeed?searchName=Frozener' + self.last_item = None + self.check_rss.start() + + @tasks.loop(minutes=1) + async def check_rss(self): + feed = feedparser.parse(self.rss_url) + latest_item = feed.entries[0] if feed.entries else None + + if latest_item and latest_item.title != self.last_item: + self.last_item = latest_item.title + channel = self.bot.get_channel(895388842834673696) + await channel.send(f"New RSS Item: {latest_item.title} - {latest_item.link}") + + @check_rss.before_loop + async def before_check_rss(self): + await self.bot.wait_until_ready() + +async def setup(bot): + await bot.add_cog(RSSCog(bot)) \ No newline at end of file From 7eee640b17f3c45a22152f81696d05f551ca98fb Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 18:28:45 -0800 Subject: [PATCH 64/76] now work with multiple usernames --- cogs/rss_feeds.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index b59d55e..220fd77 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -7,19 +7,22 @@ class RSSCog(BotBaseCog): def __init__(self, bot): super().__init__(bot) self.setup(__class__.__name__) - self.rss_url = 'https://secure.runescape.com/m=adventurers-log/rssfeed?searchName=Frozener' - self.last_item = None + self.rss_base_url = 'https://secure.runescape.com/m=adventurers-log/rssfeed?searchName=' + self.usernames = ['Deadifyed', 'Frozener'] + self.last_items = {'Deadifyed':None, 'Frozener':None} self.check_rss.start() @tasks.loop(minutes=1) async def check_rss(self): - feed = feedparser.parse(self.rss_url) - latest_item = feed.entries[0] if feed.entries else None - - if latest_item and latest_item.title != self.last_item: - self.last_item = latest_item.title - channel = self.bot.get_channel(895388842834673696) - await channel.send(f"New RSS Item: {latest_item.title} - {latest_item.link}") + for name in self.usernames: + rss_url = self.rss_base_url + name + feed = feedparser.parse(rss_url) + latest_item = feed.entries[0] if feed.entries else None + + if latest_item and latest_item.title != self.last_items[name]: + self.last_items[name] = latest_item.title + channel = self.bot.get_channel(895388842834673696) + await channel.send(f"New RSS Item: {latest_item.title} - {latest_item.link}") @check_rss.before_loop async def before_check_rss(self): From c5fdb36fc4ff91fe8f5098102cbc8df219f0f89a Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 18:30:14 -0800 Subject: [PATCH 65/76] added feedparser to requirements --- cogs/rss_feeds.py | 2 +- requirements.txt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index 220fd77..bcf5713 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -22,7 +22,7 @@ class RSSCog(BotBaseCog): if latest_item and latest_item.title != self.last_items[name]: self.last_items[name] = latest_item.title channel = self.bot.get_channel(895388842834673696) - await channel.send(f"New RSS Item: {latest_item.title} - {latest_item.link}") + await channel.send(f"{name}: {latest_item.title} - {latest_item.link}") @check_rss.before_loop async def before_check_rss(self): diff --git a/requirements.txt b/requirements.txt index 6645a76..afdebf7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,5 @@ inky wakeonlan beautifulsoup4 Flask[async] -waitress \ No newline at end of file +waitress +feedparser \ No newline at end of file From 43da4a23888595ae64b107ea01176c96af14190d Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 18:44:48 -0800 Subject: [PATCH 66/76] Send description rather than title + cleanup --- cogs/rss_feeds.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index bcf5713..ecbbef4 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -8,8 +8,8 @@ class RSSCog(BotBaseCog): super().__init__(bot) self.setup(__class__.__name__) self.rss_base_url = 'https://secure.runescape.com/m=adventurers-log/rssfeed?searchName=' - self.usernames = ['Deadifyed', 'Frozener'] - self.last_items = {'Deadifyed':None, 'Frozener':None} + self.usernames = ['Deadifyed', 'Frozener', 'Tsuki no ko', 'blue boomer4'] + self.last_items = {key: None for key in self.usernames} self.check_rss.start() @tasks.loop(minutes=1) @@ -22,7 +22,7 @@ class RSSCog(BotBaseCog): if latest_item and latest_item.title != self.last_items[name]: self.last_items[name] = latest_item.title channel = self.bot.get_channel(895388842834673696) - await channel.send(f"{name}: {latest_item.title} - {latest_item.link}") + await channel.send(f"{name}: {latest_item.description}") @check_rss.before_loop async def before_check_rss(self): From 78e9cd58076eb3588574bcee20b8d74cb2207135 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 18:49:09 -0800 Subject: [PATCH 67/76] removed usernames with spaces --- cogs/rss_feeds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index ecbbef4..a965f6e 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -8,7 +8,7 @@ class RSSCog(BotBaseCog): super().__init__(bot) self.setup(__class__.__name__) self.rss_base_url = 'https://secure.runescape.com/m=adventurers-log/rssfeed?searchName=' - self.usernames = ['Deadifyed', 'Frozener', 'Tsuki no ko', 'blue boomer4'] + self.usernames = ['Deadifyed', 'Frozener'] self.last_items = {key: None for key in self.usernames} self.check_rss.start() From f4a92db44021f6c0f3a291d8056fca782c7a72f6 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 19:13:33 -0800 Subject: [PATCH 68/76] Now works with names with spaces --- cogs/rss_feeds.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index a965f6e..14f62b9 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -8,14 +8,14 @@ class RSSCog(BotBaseCog): super().__init__(bot) self.setup(__class__.__name__) self.rss_base_url = 'https://secure.runescape.com/m=adventurers-log/rssfeed?searchName=' - self.usernames = ['Deadifyed', 'Frozener'] + self.usernames = ['Deadifyed', 'Frozener', 'Tsuki no ko', 'blue boomer4'] self.last_items = {key: None for key in self.usernames} self.check_rss.start() @tasks.loop(minutes=1) async def check_rss(self): for name in self.usernames: - rss_url = self.rss_base_url + name + rss_url = self.rss_base_url + name.replace(' ','%A0') feed = feedparser.parse(rss_url) latest_item = feed.entries[0] if feed.entries else None From 0271854cbb54b17c47f281e4739aeb127b21382e Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 19:26:12 -0800 Subject: [PATCH 69/76] changed %A0 to %A20 to try to get spaces in names to work --- cogs/rss_feeds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index 14f62b9..a9e3f3b 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -15,7 +15,7 @@ class RSSCog(BotBaseCog): @tasks.loop(minutes=1) async def check_rss(self): for name in self.usernames: - rss_url = self.rss_base_url + name.replace(' ','%A0') + rss_url = self.rss_base_url + name.replace(' ','%20') feed = feedparser.parse(rss_url) latest_item = feed.entries[0] if feed.entries else None From 0736ea2d43e849d2c0428c0c28add77a45e53503 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 19:27:12 -0800 Subject: [PATCH 70/76] removed names with spaces for now --- cogs/rss_feeds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index a9e3f3b..1a88b90 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -8,7 +8,7 @@ class RSSCog(BotBaseCog): super().__init__(bot) self.setup(__class__.__name__) self.rss_base_url = 'https://secure.runescape.com/m=adventurers-log/rssfeed?searchName=' - self.usernames = ['Deadifyed', 'Frozener', 'Tsuki no ko', 'blue boomer4'] + self.usernames = ['Deadifyed', 'Frozener'] self.last_items = {key: None for key in self.usernames} self.check_rss.start() From 7348ffeccba89288c37f9518e7e0967524be090e Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 19:28:11 -0800 Subject: [PATCH 71/76] removed the name.replace() --- cogs/rss_feeds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index 1a88b90..1df978d 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -15,7 +15,7 @@ class RSSCog(BotBaseCog): @tasks.loop(minutes=1) async def check_rss(self): for name in self.usernames: - rss_url = self.rss_base_url + name.replace(' ','%20') + rss_url = self.rss_base_url + name#.replace(' ','%20') feed = feedparser.parse(rss_url) latest_item = feed.entries[0] if feed.entries else None From 4b55b0e6f71851114a8b2dedaf5c2b009aefafa4 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 19:41:08 -0800 Subject: [PATCH 72/76] This code works with multiple usernames. Jagex website is trash though --- cogs/rss_feeds.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index 1df978d..a9e3f3b 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -8,14 +8,14 @@ class RSSCog(BotBaseCog): super().__init__(bot) self.setup(__class__.__name__) self.rss_base_url = 'https://secure.runescape.com/m=adventurers-log/rssfeed?searchName=' - self.usernames = ['Deadifyed', 'Frozener'] + self.usernames = ['Deadifyed', 'Frozener', 'Tsuki no ko', 'blue boomer4'] self.last_items = {key: None for key in self.usernames} self.check_rss.start() @tasks.loop(minutes=1) async def check_rss(self): for name in self.usernames: - rss_url = self.rss_base_url + name#.replace(' ','%20') + rss_url = self.rss_base_url + name.replace(' ','%20') feed = feedparser.parse(rss_url) latest_item = feed.entries[0] if feed.entries else None From e978ed66439015cc997ca236c2f3c360a71db361 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 19:56:32 -0800 Subject: [PATCH 73/76] slow down checking so maybe it doesnt 404 as much --- cogs/rss_feeds.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index a9e3f3b..57e23d6 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -1,6 +1,7 @@ from discord.ext import commands, tasks from cogs.base_cog.bot_base_cog import BotBaseCog import feedparser +import asyncio class RSSCog(BotBaseCog): @@ -12,7 +13,7 @@ class RSSCog(BotBaseCog): self.last_items = {key: None for key in self.usernames} self.check_rss.start() - @tasks.loop(minutes=1) + @tasks.loop(minutes=5) async def check_rss(self): for name in self.usernames: rss_url = self.rss_base_url + name.replace(' ','%20') @@ -23,6 +24,8 @@ class RSSCog(BotBaseCog): self.last_items[name] = latest_item.title channel = self.bot.get_channel(895388842834673696) await channel.send(f"{name}: {latest_item.description}") + + asyncio.sleep(60) @check_rss.before_loop async def before_check_rss(self): From f4b1280d9a0eb335f29842946505ef5f9de458b9 Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 19:59:54 -0800 Subject: [PATCH 74/76] now sleeps correctly --- cogs/rss_feeds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index 57e23d6..657e237 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -25,7 +25,7 @@ class RSSCog(BotBaseCog): channel = self.bot.get_channel(895388842834673696) await channel.send(f"{name}: {latest_item.description}") - asyncio.sleep(60) + asyncio.sleep(60) @check_rss.before_loop async def before_check_rss(self): From 7bb423445d6957d33f1eb00e7b0bdeb8cc499c1d Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 1 Jan 2025 20:07:37 -0800 Subject: [PATCH 75/76] correctly await asyncio --- cogs/rss_feeds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/rss_feeds.py b/cogs/rss_feeds.py index 657e237..fd5fff6 100644 --- a/cogs/rss_feeds.py +++ b/cogs/rss_feeds.py @@ -25,7 +25,7 @@ class RSSCog(BotBaseCog): channel = self.bot.get_channel(895388842834673696) await channel.send(f"{name}: {latest_item.description}") - asyncio.sleep(60) + await asyncio.sleep(60) @check_rss.before_loop async def before_check_rss(self): From da2559e704c53625b41e93590771868a9db1597b Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 23 Jan 2025 15:18:44 -0800 Subject: [PATCH 76/76] Removed budget and gpt4 commands as they were useless --- cogs/chatgpt.py | 66 ------------------------------------------------- 1 file changed, 66 deletions(-) diff --git a/cogs/chatgpt.py b/cogs/chatgpt.py index 8559a2f..70c3768 100644 --- a/cogs/chatgpt.py +++ b/cogs/chatgpt.py @@ -23,7 +23,6 @@ class ChatGPT(commands.Cog): self.folder_setup() self.remind_me_loop.start() self.http_session = self.create_aiohttp_session() - self.dalle_budget = self.get_budget() self.logger = logging.getLogger("bot") self.headers = { 'Content-Type': 'application/json', @@ -61,36 +60,6 @@ class ChatGPT(commands.Cog): output_cost = cost_table[model]["output_tokens"] * output_tokens cost = input_cost + output_cost return cost - - def get_budget(self): - month = time.strftime("%B") - year = time.strftime("%Y") - key = f"{month}_{year}" - budget_file = f"{self.data_dir}budget.json" - if not os.path.exists(budget_file): - with open(budget_file, "w") as f: - json.dump({key:self.default_budget},f) - with open(budget_file, "r") as f: - budget_dict = json.loads(f.readline()) - if key not in budget_dict: - budget_dict[key] = self.default_budget - with open(budget_file, "w") as f: - json.dump(budget_dict,f) - return self.default_budget - else: - return budget_dict[key] - - def budget_add(self, amount): - month = time.strftime("%B") - year = time.strftime("%Y") - key = f"{month}_{year}" - budget_file = f"{self.data_dir}budget.json" - with open(budget_file, "r") as f: - budget_dict = json.loads(f.readline()) - budget_dict[key] += amount - with open(budget_file, "w") as f: - json.dump(budget_dict,f) - self.dalle_budget += amount def add_cost(self, category: str, cost: float): day = time.strftime("%d") @@ -155,28 +124,6 @@ class ChatGPT(commands.Cog): categories = response_data['results'][0]['categories'] category_scores = response_data['results'][0]['category_scores'] return (flagged, categories, category_scores) - - @commands.command() - async def budget(self, ctx, command=None, budget=None): - try: - if ctx.author.id == self.admin_id: - if command == "add" and budget!= None: - self.budget_add(float(budget)) - await ctx.send(f"Budget increased by {budget}") - elif command == "remove" and budget!= None: - self.budget_add(-float(budget)) - await ctx.send(f"Budget decreased by {budget}") - elif command == "set" and budget!= None: - self.budget_add(float(budget) - self.dalle_budget) - await ctx.send(f"Budget set to {budget}") - else: - await ctx.send(f"The current budget is {self.dalle_budget}") - else: - await ctx.send(f"The current budget is {self.dalle_budget}") - except Exception as e: - self.logger.exception(f"Budget command failed: {e}") - await ctx.send(f"Budget command failed") - @commands.command( name="costs", @@ -421,19 +368,6 @@ class ChatGPT(commands.Cog): chunks = [answer[i:i+1999] for i in range(0, len(answer), 1999)] for chunk in chunks: await ctx.send(chunk) - - @commands.command( - description="Question GPT4", - help="Ask GPT4 a question. Usage: !question_gpt4 (question)", - brief="Get an answer" - ) - async def question_gpt4(self, ctx): - await ctx.send("One moment, let me think...") - question = ctx.message.content.split(" ", maxsplit=1)[1] - answer = await self.answer_question(question, "gpt-4o") - chunks = [answer[i:i+1999] for i in range(0, len(answer), 1999)] - for chunk in chunks: - await ctx.send(chunk) async def dalle_api_call(self, prompt: str, model: str="dall-e-2", quality: str="standard", size: str="1024x1024") -> tuple: if self.dalle_budget <= await self.get_monthly_cost():