diff --git a/extensions/phixxycom.py b/extensions/phixxycom.py index 7703506..0d9e0a2 100644 --- a/extensions/phixxycom.py +++ b/extensions/phixxycom.py @@ -2,6 +2,7 @@ import os import io import base64 import time +import json import asyncssh from PIL import Image, PngImagePlugin from discord.ext import commands, tasks @@ -16,6 +17,7 @@ class PhixxyCom(commands.Cog): self.working_dir = "tmp/phixxy.com/" self.data_dir = "data/phixxy.com/" self.folder_setup() + self.stable_diffusion_log = "data/stable_diffusion/stable_diffusion.log" self.phixxy_loop.start() def folder_setup(self): @@ -27,6 +29,15 @@ class PhixxyCom(commands.Cog): except: print("PhixxyCom failed to make directories") + def find_prompt_from_filename(sd_log, filename): + with open(sd_log, 'r') as f: + lines = f.readlines() + for line in reversed(lines): + if filename in line: + prompt = line[line.index("Prompt: ") + 7:line.index("Filename: ")] + return prompt + return "Unknown Prompt" + async def upload_sftp(self, local_filename, server_folder, server_filename): remotepath = server_folder + server_filename async with asyncssh.connect(self.SERVER, username=self.USERNAME, password=self.PASSWORD) as conn: @@ -141,8 +152,7 @@ class PhixxyCom(commands.Cog): for filename in os.listdir(folder): if filename[-4:] == '.png': filepath = folder + filename - prompt = "Unknown Prompt" # Will have to update this later - + prompt = self.find_prompt_from_filename(self.stable_diffusion_log, filename) html_file = "phixxy.com/ai-images/index.html" html_insert = '''
diff --git a/extensions/stable_diffusion.py b/extensions/stable_diffusion.py index 19c217b..48f1a23 100644 --- a/extensions/stable_diffusion.py +++ b/extensions/stable_diffusion.py @@ -257,11 +257,12 @@ class StableDiffusion(commands.Cog): folder = self.working_dir + "sfw/" except: folder = self.working_dir - my_filename = folder + str(time.time_ns()) + ".png" - image.save(my_filename, pnginfo=pnginfo) + my_filename = str(time.time_ns()) + ".png" + filepath = folder + my_filename + image.save(filepath, pnginfo=pnginfo) - with open(my_filename, "rb") as fh: - f = discord.File(fh, filename=my_filename) + with open(filepath, "rb") as fh: + f = discord.File(fh, filename=filepath) log_data = f'Author: {ctx.author.name}, Prompt: {prompt}, Filename: {my_filename}\n' with open(f"{self.data_dir}stable_diffusion.log", 'a') as log_file: diff --git a/sparkytron3000.py b/sparkytron3000.py index 06cf6ac..357eca7 100644 --- a/sparkytron3000.py +++ b/sparkytron3000.py @@ -30,7 +30,7 @@ ftp_public_html = os.getenv('ftp_public_html') #discord setup START intents = discord.Intents.default() intents.message_content = True -bot = commands.Bot(command_prefix='?', intents=intents) +bot = commands.Bot(command_prefix='!', intents=intents) #discord setup END @@ -242,7 +242,7 @@ async def on_message(ctx): await react_to_msg(ctx, channel_vars["react_to_msgs"]) #emoji reactions - if channel_vars["commands_enabled"] or (ctx.author.id == 242018983241318410 and ctx.content[0] == "?"): + if channel_vars["commands_enabled"] or (ctx.author.id == 242018983241318410 and ctx.content[0] == "!"): await bot.process_commands(ctx) if not channel_vars["commands_enabled"]: await ctx.channel.send("This command only ran because you set it to allow to run even when commands are disabled")