Not saving file to the directory anymore. Sending as a bytes object

pull/8/head
sgoudham 4 years ago
parent da5e9c8a89
commit 25f1937593

@ -1,6 +1,5 @@
import datetime import datetime
import io import io
import os
import random import random
import string import string
import textwrap import textwrap
@ -59,7 +58,10 @@ def generate_meme(image_path, top_text, bottom_text='', font_path='homies/impact
y += line_height y += line_height
# Save meme # Save meme
get_image.save(f"AllMyHomiesHateMeme{counter}.jpg") file = io.BytesIO()
get_image.save(file, format='PNG')
file.seek(0)
return file
# Set up the cog # Set up the cog
@ -348,33 +350,21 @@ class Fun(Cog):
# Global counter for saving homies meme # Global counter for saving homies meme
global counter global counter
try: # Make sure the text entered is less than 20 characters
# Make sure the text entered is less than 20 characters if len(text) >= 20:
if len(text) >= 20: await ctx.send("Please make sure the prompt is below **20** characters!")
await ctx.send("Please make sure the prompt is below **20** characters!") return
return else:
else:
# Define the text to be drawn on the top and the bottom
top_text = f"Ayo fuck {text}"
bottom_text = f"All my homies hate {text}"
# Call the method to generate the image
generate_meme('homies/AllMyHomies.jpg', top_text=top_text, bottom_text=bottom_text)
# Send the image file stored in the directory # Define the text to be drawn on the top and the bottom
await ctx.send(file=discord.File(f'AllMyHomiesHateMeme{counter}.jpg')) top_text = f"Ayo fuck {text}"
bottom_text = f"All my homies hate {text}"
# Remove file after sending it and then increment the counter # Call the method to generate the image
path = f"AllMyHomiesHateMeme{counter}.jpg" file = generate_meme('homies/AllMyHomies.jpg', top_text=top_text, bottom_text=bottom_text)
if os.path.exists(path):
os.remove(path)
counter += 1
else:
print("The file does not exist")
except Exception as e: # Send the image file stored in the directory
print(e) await ctx.send(file=discord.File(file, "homies.png"))
@command(name="owo", aliases=["Owo", "OwO"]) @command(name="owo", aliases=["Owo", "OwO"])
@cooldown(1, 1, BucketType.user) @cooldown(1, 1, BucketType.user)
@ -408,7 +398,6 @@ class Fun(Cog):
await ctx.send(text) await ctx.send(text)
else: else:
embed = Embed(description="**Image Not Detected!**", embed = Embed(description="**Image Not Detected!**",
colour=enso_embedmod_colours) colour=enso_embedmod_colours)

Loading…
Cancel
Save