Removed the image ability

This commit is contained in:
unknown 2023-06-03 18:05:40 +02:00
parent 133048120f
commit 1bc94bfd9c

View File

@ -128,58 +128,6 @@ class ReginaldCog(commands.Cog):
response_text = response_text[split_index:].strip()
chunks.append(response_text)
return chunks
@commands.guild_only()
@has_admin_role()
@commands.command(help="Ask Reginald to generate an image based on a prompt")
@commands.cooldown(1, 300, commands.BucketType.user) # 5-minute cooldown per user
async def reginaldimagine(self, ctx, *, prompt=None):
if prompt is None:
await ctx.author.send("Please provide a prompt for the image.")
return
api_key = await self.config.guild(ctx.guild).openai_api_key()
if api_key is None:
await ctx.author.send('OpenAI API key not set. Please use the "!setreginaldcogapi" command to set the key.')
return
try:
image_url = await self.generate_image(api_key, prompt)
if image_url:
async with ctx.typing():
async with aiohttp.ClientSession() as session:
async with session.get(image_url) as resp:
image_data = await resp.read()
image = Image.open(BytesIO(image_data))
with tempfile.TemporaryDirectory() as temp_dir:
image_path = os.path.join(temp_dir, "image.png")
image.save(image_path)
await ctx.send(file=discord.File(image_path))
else:
await ctx.author.send("I apologize, but I am unable to generate an image based on the provided prompt.")
except Exception as e:
await ctx.author.send(f"I apologize, but I am unable to generate an image at this time. Error message: {str(e)}")
async def generate_image(self, api_key, prompt):
url = "https://api.openai.com/v1/images/generations"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
}
data = {
"prompt": prompt,
"n": 1,
"size": "512x512",
}
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, data=json.dumps(data)) as resp:
response = await resp.json()
if response and "data" in response and len(response["data"]) > 0:
return response["data"][0]["url"]
return None
@reginald.error
async def reginald_error(self, ctx, error):
@ -190,15 +138,6 @@ class ReginaldCog(commands.Cog):
else:
await ctx.author.send(f"An unexpected error occurred: {error}")
@reginaldimagine.error
async def reginaldimagine_error(self, ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.author.send("I'm sorry, but I couldn't understand your input. Please check your message and try again.")
elif isinstance(error, commands.CheckFailure):
await ctx.author.send("You do not have the required role to use this command.")
else:
await ctx.author.send(f"An unexpected error occurred: {error}")
def setup(bot):
cog = ReginaldCog(bot)
bot.add_cog(cog)