async def draw_universal(ctx, path, command_end_index, origin, name): """Universal function which is called by draw command with the following arguments Args: - ctx: context that the command occured use this to access the message and other attributes - path: path to the drawing image (ie memes/lan/landrew.png) - command_end_index: index the end of the command (ie. for bdraw its 7 for '$' 'b' 'd' 'r' 'a' 'w' ' ') - origin: pixel origin imported from overlay.py - name: output file name """ channel = ctx.channel async with channel.typing(): url = over.get_image_url(ctx.message, command_end_index) if url == 0: # no url, hand should write the inputed text if len(ctx.message.content[command_end_index:].strip()) == 0: # no input given, try to use previous bot output if bot_last_command[ctx.author.id] is not None: message = bot_last_command[ctx.author.id] url = over.get_image_url(message, 0) output = over.overlay_image(over.url_to_image(url), Path(path), origin) else: await channel.send(embed=discord.Embed( description= "No previous bot command to pull from. Please specify text or an image.", color=discord.Color.red())) return else: output = over.draw_text( ctx.message.content[command_end_index:], Path(path), origin) else: # url inputed, hand should draw on the image output = over.overlay_image(over.url_to_image(url), Path(path), origin) output.save(name + '.png') try: message = await channel.send(file=discord.File(name + '.png')) except: message = await channel.send(embed=discord.Embed( description="Image too large", color=discord.Color.red())) track_command(ctx.author.id, message) # tracks the most recent command of a user os.remove(name + '.png')
async def draw_universal(ctx, path, command_end_index, origin, name): """Universal function which is called by draw command with the following arguments Args: - ctx: context that the command occured use this to access the message and other attributes - path: path to the drawing image (ie memes/lan/landrew.png) - command_end_index: index the end of the command (ie. for bdraw its 7 for '$' 'b' 'd' 'r' 'a' 'w' ' ') - origin: pixel origin imported from overlay.py - name: output file name """ channel = ctx.channel #in case of gif url = over.get_gif_url(ctx, command_end_index) if url != 0: #get list of frames imgList = over.gif_url_to_image_list(url, 1) if imgList == 0: #if invalid list return await channel.send(embed=discord.Embed(description="invalid image", color=discord.Color.red())) return #get list of image clips gifClip = make_draw_gif(imgList, 0) gifClip.write_gif(name + '.gif', 24, program='imageio') try: #check if message is <8 mb message = await channel.send(file=discord.File(name + '.gif')) except: #random color cause why not randRGB = lambda: random.randint(0, 255) randColor = int('%02X%02X%02X' % (randRGB(), randRGB(), randRGB()), 16) os.remove(name + '.gif') await channel.send(embed=discord.Embed( description="GIF + image becomes too large to send, sorry :(", color=randColor)) return track_command(ctx.author.id, message) os.remove(name + '.gif') return url = over.get_image_url(ctx, command_end_index) if url == 0: # no url, hand should write the inputed text output = over.draw_text(ctx.message.content[command_end_index:], Path(path), origin) else: # url inputed, hand should draw on the image output = over.overlay_image(over.url_to_image(url), Path(path), origin) output.save(name + '.png') try: message = await channel.send(file=discord.File(name + '.png')) except: message = await channel.send(embed=discord.Embed( description="Image too large", color=discord.Color.red())) track_command(ctx.author.id, message) # tracks the most recent command of a user os.remove(name + '.png')
async def bdraw(ctx): url = get_image_url(ctx) if url == 0: output = draw_text(ctx.message.content[7:], Path('memes/barrington/bdraw.png')) else: output = overlay_image(url_to_image(url), Path('memes/barrington/bdraw.png')) output.save('barrington-drawing.png') await client.send_file(ctx.message.channel, 'barrington-drawing.png') os.remove('barrington-drawing.png')
async def mdraw(ctx): url = get_image_url(ctx) if url == 0: output = draw_text(ctx.message.content[7:], Path('memes/marius/draw.png')) else: output = overlay_image(url_to_image(url), Path('memes/marius/draw.png')) name = 'marius-drawing.png' output.save(name) await client.send_file(ctx.message.channel, name) os.remove(name)
async def bdraw(ctx): url = get_image_url(ctx) if url == 0: output = draw_text(ctx.message.content[7:], Path('memes/barrington/bdraw.png'), barr_origin) else: output = overlay_image(url_to_image(url), Path('memes/barrington/bdraw.png'), barr_origin) output.save('barrington-drawing.png') message = await client.send_file(ctx.message.channel, 'barrington-drawing.png') track_command(ctx.message.author.id, message) os.remove('barrington-drawing.png')
async def mdraw(ctx): url = get_image_url(ctx) if url == 0: output = draw_text(ctx.message.content[7:], Path('memes/marius/draw.png'), marius_origin) else: output = overlay_image(url_to_image(url), Path('memes/marius/draw.png'), marius_origin) name = 'marius-drawing.png' output.save(name) message = await client.send_file(ctx.message.channel, name) track_command(ctx.message.author.id, message) os.remove(name)
async def barrify(ctx): url = get_image_url(ctx) if url == 0: # invalid image await client.send_message(ctx.message.channel, embed=discord.Embed( description="Invalid image", color=discord.Color.red())) return else: output = paste_on_face(Path('memes/barrington/barr-face.png'), url) output.save('barrify.png') message = await client.send_file(ctx.message.channel, 'barrify.png') track_command(ctx.message.author.id, message) os.remove('barrify.png')
async def ify(ctx, scale, path, file_name, *args): """Command to paste a face on top of faces in an inputed image using facial recognition Args: - ctx: context that the command occured use this to access the message and other attributes - args: arguments of the message - scale: specified scale for the faces - path: face image path - file_name: output file name """ channel = ctx.channel async with channel.typing(): url = over.get_image_url_args(ctx.message, args[0], 1, 0) if url == 0: # invalid image # no input given, try to use previous bot output if bot_last_command[ctx.author.id] is not None: message = bot_last_command[ctx.author.id] url = over.get_image_url(message, 0) else: await channel.send(embed=discord.Embed( description= "No previous bot command to pull from. Please specify a valid image.", color=discord.Color.red())) return try: output = paste_on_face(Path(path), url, scale) except: await channel.send(embed=discord.Embed( description='Unidentified Image, try a different image', color=discord.Color.red())) # if there were no faces found then send error if output == 0: await channel.send(embed=discord.Embed( description='No faces found, please input another image', color=discord.Color.red())) return output.save(file_name) try: message = await channel.send(file=discord.File(file_name)) track_command(ctx.author.id, message) except: await channel.send(embed=discord.Embed( description="Image too large", color=discord.Color.red())) os.remove(file_name)
async def noise_filter(ctx): """Command to apply a noise filter on the inputted image Args: - ctx: context that the command occured use this to access the message and other attributes """ channel = ctx.channel url = overlay.get_image_url(ctx, 7) if url == 0: await channel.send(embed=discord.Embed(description="Invalid Image", color=discord.Color.red())) return output = filters.scramble_pixels(overlay.url_to_image(url)) output.save('noise.png') try: message = await channel.send(file=discord.File('noise.png')) except: message = await channel.send(embed=discord.Embed( description="Image too large", color=discord.Color.red())) custom_meme.track_command(ctx.author.id, message) os.remove('noise.png')
async def make_okay(ctx): """Command to turn a given image into a video where marius says 'okay' in the background Args: - ctx: context that the command occured use this to access the message and other attributes """ channel = ctx.channel url = overlay.get_image_url(ctx, 6) if url == 0: await channel.send(embed=discord.Embed(description="Invalid Image", color=discord.Color.red())) return clip = filters.make_okay_clip(overlay.url_to_image(url)) clip.write_videofile("okay.mp4", audio="sfx/okayturnedupto8.mp3", fps=24) try: message = await channel.send(file=discord.File("okay.mp4")) except: message = await channel.send(embed=discord.Embed( description="Image too large", color=discord.Color.red())) custom_meme.track_command(ctx.author.id, message) os.remove("okay.mp4")
async def zoomcam(ctx, path, file_name, *args): """Command to paste a a zoomer in the corner of an image Args: - ctx: context that the command occured use this to access the message and other attributes - path: zoomer image path - file_name: output file name - args: arguments of the message """ channel = ctx.channel async with channel.typing(): url = over.get_image_url_args(ctx.message, args[0], 1, 0) if url == 0: # invalid image # no input given, try to use previous bot output if bot_last_command[ctx.author.id] is not None: message = bot_last_command[ctx.author.id] url = over.get_image_url(message, 0) else: await channel.send(embed=discord.Embed( description= "No previous bot command to pull from. Please specify a valid image.", color=discord.Color.red())) return output = over.paste_in_streamer_corner(Path(path), url) if output == 0: await channel.send(embed=discord.Embed( description= "Encountered issue converting image to RGBA, please try a different image", color=discord.Color.red())) return output.save(file_name) try: message = await channel.send(file=discord.File(file_name)) track_command(ctx.author.id, message) except: await channel.send(embed=discord.Embed( description="Image too large", color=discord.Color.red())) os.remove(file_name)