diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index bade54d..c2e1b55 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,6 +1,6 @@ # These are supported funding model platforms -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +github: [Kav-K] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username @@ -10,4 +10,4 @@ liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry -custom: https://paypal.me/kaveenkk9 +custom: #Nothing diff --git a/README.md b/README.md index 2bf0e36..1873c72 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,12 @@ cd GPT3Discord/ sudo apt-get update sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa -sudo apt install python3.9 python3.9-pip +sudo apt install python3.9 +sudo apt install python3.9-distutils # If this doesn't work, try sudo apt install python3-distutils + +# Install Pip for python3.9 +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py +python3.9 get-pip.py # Install project dependencies python3.9 -m pip install -r requirements.txt @@ -125,6 +130,18 @@ screen gpt3discord screen -r ``` +If the last few commands don't allow the bot to run `screen gpt3discord`, you can attempt to run the bot another way: +```bash +{Navigate to the folder where the project files are} +screen -dmS GPTBot bash -c 'python3.9 gpt3discord.py' + +# Reattach to screen session +screen -x # will reattach if this is the only screen session, if there are multiple, it will show IDs +# If there are multiple IDs returned by screen -x: +screen -d -r {ID} # replace {ID} with the ID of the screen session you want to reattach to + +``` + ## Docker Installation We now have a `Dockerfile` in the repository. This will build / install all dependencies and put a `gpt3discord` binary (main.py) into path. @@ -200,4 +217,4 @@ This can also be run via screen/tmux or detached like a daemon. # Configuration -All the model parameters are configurable inside discord. Type `!gp` to view all the configurable parameters, and use `/settings ` to set parameters. For example, if I wanted to change the number of images generated by DALL-E by default to 4, I can type the following command in discord: `/settings num_images 4` +All the model parameters are configurable inside discord. Type `/settings` to view all the configurable parameters, and use `/settings ` to set parameters. For example, if I wanted to change the number of images generated by DALL-E by default to 4, I can type the following command in discord: `/settings num_images 4` diff --git a/cogs/draw_image_generation.py b/cogs/draw_image_generation.py index 2c39c3a..3b4a68b 100644 --- a/cogs/draw_image_generation.py +++ b/cogs/draw_image_generation.py @@ -75,7 +75,7 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"): ) await result_message.edit( - view=SaveView(image_urls, self, self.converser_cog, result_message) + view=SaveView(ctx, image_urls, self, self.converser_cog, result_message) ) self.converser_cog.users_to_interactions[user_id] = [] @@ -94,7 +94,7 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"): file=file, ) await message.edit( - view=SaveView(image_urls, self, self.converser_cog, message) + view=SaveView(ctx, image_urls, self, self.converser_cog, message) ) else: # Varying case if not draw_from_optimizer: @@ -105,7 +105,12 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"): ) await result_message.edit( view=SaveView( - image_urls, self, self.converser_cog, result_message, True + ctx, + image_urls, + self, + self.converser_cog, + result_message, + True, ) ) @@ -117,7 +122,7 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"): ) await result_message.edit( view=SaveView( - image_urls, self, self.converser_cog, result_message + ctx, image_urls, self, self.converser_cog, result_message ) ) @@ -200,11 +205,19 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"): class SaveView(discord.ui.View): def __init__( - self, image_urls, cog, converser_cog, message, no_retry=False, only_save=None + self, + ctx, + image_urls, + cog, + converser_cog, + message, + no_retry=False, + only_save=None, ): super().__init__( timeout=3600 if not only_save else None - ) # 10 minute timeout for Retry, Save + ) # 1 hour timeout for Retry, Save + self.ctx = ctx self.image_urls = image_urls self.cog = cog self.no_retry = no_retry @@ -230,6 +243,7 @@ class SaveView(discord.ui.View): # Create a new view with the same params as this one, but pass only_save=True new_view = SaveView( + self.ctx, self.image_urls, self.cog, self.converser_cog, @@ -239,7 +253,7 @@ class SaveView(discord.ui.View): ) # Set the view of the message to the new view - await self.message.edit(view=new_view) + await self.ctx.edit(view=new_view) class VaryButton(discord.ui.Button): diff --git a/cogs/gpt_3_commands_and_converser.py b/cogs/gpt_3_commands_and_converser.py index 6de33d6..1846139 100644 --- a/cogs/gpt_3_commands_and_converser.py +++ b/cogs/gpt_3_commands_and_converser.py @@ -625,12 +625,12 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"): response_message = ( await ctx.respond( response_text, - view=RedoView(self, user_id), + view=RedoView(ctx, self, user_id), ) if from_context else await ctx.reply( response_text, - view=RedoView(self, user_id), + view=RedoView(ctx, self, user_id), ) ) @@ -890,9 +890,10 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"): class RedoView(discord.ui.View): - def __init__(self, converser_cog, user_id): + def __init__(self, ctx, converser_cog, user_id): super().__init__(timeout=3600) # 1 hour interval to redo. self.converser_cog = converser_cog + self.ctx = ctx self.add_item(RedoButton(self.converser_cog)) if user_id in self.converser_cog.conversating_users: @@ -902,9 +903,14 @@ class RedoView(discord.ui.View): # Remove the button from the view/message self.clear_items() # Send a message to the user saying the view has timed out - await self.message.edit( - view=None, - ) + if self.message: + await self.message.edit( + view=None, + ) + else: + await self.ctx.edit( + view=None, + ) class EndConvoButton(discord.ui.Button["RedoView"]): diff --git a/gpt3discord.py b/gpt3discord.py index 6ad704d..95caabc 100644 --- a/gpt3discord.py +++ b/gpt3discord.py @@ -6,6 +6,15 @@ from pathlib import Path import discord from dotenv import load_dotenv from pycord.multicog import apply_multicog +import os + +if sys.platform == "win32": + separator = "\\" +else: + separator = "/" + +print("The environment file is located at " + os.getcwd() + separator + ".env") +load_dotenv(dotenv_path=os.getcwd() + separator + ".env") from cogs.draw_image_generation import DrawDallEService from cogs.gpt_3_commands_and_converser import GPT3ComCon @@ -15,9 +24,7 @@ from models.message_model import Message from models.openai_model import Model from models.usage_service_model import UsageService -__version__ = "2.1.2" -load_dotenv() -import os +__version__ = "2.1.3" """ Message queueing for the debug service, defer debug messages to be sent later so we don't hit rate limits. diff --git a/pyproject.toml b/pyproject.toml index 954e5e4..6aa5cb1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,8 +18,6 @@ classifiers = [ "Programming Language :: Python :: 3.9", ] dependencies = [ - "asgiref", - "openai", "Pillow", "py-cord", "python-dotenv", diff --git a/requirements.txt b/requirements.txt index 67d6ace..808b97a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,3 @@ -asgiref==3.6.0 -openai==0.25.0 Pillow==9.3.0 py-cord==2.3.2 python-dotenv==0.21.0